Skip to content

Instantly share code, notes, and snippets.

@amree
Last active January 28, 2025 04:44
Show Gist options
  • Save amree/e0b2e0d8ea6c78dadb837fbbf83d19f3 to your computer and use it in GitHub Desktop.
Save amree/e0b2e0d8ea6c78dadb837fbbf83d19f3 to your computer and use it in GitHub Desktop.
PostgreSQL Admin 101 Thread

Links

Threads
References

Commands

Docker Cheatsheet:

# Stop and delete container
docker rm -f container-name

# Enter the container using psql
docker exec -it lab-pg17 psql -U postgres

# Build the docker image
docker build -t image-name .

# Create new container
docker run --name lab-pg17 \
  -v /path/to/postgres-data:/var/lib/postgresql/data \
  -e POSTGRES_PASSWORD=secret \
  -p 5433:5432 \
  -d lab-pg17

Meta commands

\conninfo -- show connection's info
\d -- list tables/relations
\db -- list tablespaces
\du -- list users
\dx -- list extensions
\l -- show databases

PostgreSQL config files:

show hba_file; -- pg_hba.conf
show config_file; -- postgresql.conf

Reload without restarting when changing something that loads at the start:

select pg_reload_conf();

See user passwords:

select * from pg_shadow;

Change a user's password

ALTER USER amree WITH PASSWORD 'password';
\password user

See the current password encryption (md5 or scram-sha-256)

show password_encryption;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment