How to use a password file in PostgreSQL.
---
title: 'How to pass in password to pg_dump?'
subtitle: How to use a password file in PostgreSQL.
author: Stack Overflow
date: November 10, 2020
source: https://stackoverflow.com/a/2893979
snippet: https://jonlabelle.com/snippets/view/markdown/how-to-a-password-file-in-postgresql
notoc: true
---
Create a `.pgpass` file in the home directory of the account that `pg_dump` will run as.
The format is:
```plaintext
hostname:port:database:username:password
```
Then, set the file's mode to `0600`. **Otherwise, the file will be ignored.**
```bash
chmod 600 ~/.pgpass
```
See the PostgreSQL documentation [libpq-pgpass](https://www.postgresql.org/docs/current/static/libpq-pgpass.html) for more information.