Skip to content

Instantly share code, notes, and snippets.

@miranda-zhang
Last active July 5, 2018 01:11
Show Gist options
  • Save miranda-zhang/a9d5e07a6847567665165b0ff7a8b9d9 to your computer and use it in GitHub Desktop.
Save miranda-zhang/a9d5e07a6847567665165b0ff7a8b9d9 to your computer and use it in GitHub Desktop.

PostgreSQL commands

sudo -u postgres psql

help

\?

list database

\l

connect to database

\c <db name>

display table (in current database)

\dt [table name]

DESCRIBE TABLE

\d+ <table name>

display user

\du

remove user

DROP USER IF EXISTS midpoint_miranda_test;

dump database

pg_dumpall > outfile

pg_dumpall backs up each database in a given cluster, and also preserves cluster-wide data such as role and tablespace definitions.

https://www.postgresql.org/docs/9.1/static/backup-dump.html

remove db cluster

rm -rf /var/lib/pgsql/data/

reinstall db cluster

sudo -U pgsql initdb
sudo -u postgres psql < dump.sql

https://serverfault.com/q/574474/115596

Also need to add /var/lib/pgsql/data/pg_hba.conf back.

current time

select now();

change editor

export EDITOR=nano
psql database_name
\e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment