2022-05-25 13:25:51 +02:00
# Connect to Postgres Database Using Psql
2023-11-16 10:23:12 +01:00
* OPTION: connect to Postgres as admin user
2022-05-25 13:25:51 +02:00
```
2023-11-16 10:37:18 +01:00
sudo -u postgres psql -U postgres
2022-05-25 13:25:51 +02:00
```
2023-11-16 10:37:18 +01:00
* OPTION: connect to the database `database name` as user `user name`
2022-05-25 13:25:51 +02:00
```
2023-11-16 10:37:18 +01:00
psql -U < user name > -d < database name >
2022-05-25 13:25:51 +02:00
```
2023-11-16 10:37:18 +01:00
* OPTION: connect to the database `database name` as user `user name` to a remote Postgres instance at host `host name` and port `port number` (NOTE: Configure Postgres for remote connections like [this ](./postgres.md ))
2022-05-25 13:25:51 +02:00
```
2023-11-16 10:37:18 +01:00
psql -h < host name > -p < port number > -U < user name > -d < database name >
2022-05-25 13:25:51 +02:00
```