# Postgres - Useful Commands

Create a file to store login and password

```bash
cd /root
vi .pgpass
```

<table border="1" id="bkmrk-localhost%3A5432%3A%2A%3Apos" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>localhost:5432:\*:postgres:password1  
localhost:5433:\*:postgres:password1</td></tr></tbody></table>

```bash
#Use Postgres
sudo -p 5432 -u postgres psql
#Tests the conntection
sudo psql -h localhost -p 5432 -U postgres -c '\conninfo'
#Resets password
sudo -u postgres /usr/pgsql-16/bin/psql -p 5432 -c "ALTER ROLE postgres PASSWORD 'password1'"
sudo -u postgres /usr/pgsql-17/bin/psql -p 5433 -c "ALTER ROLE postgres PASSWORD 'password1'"
```