Skip to content

Instantly share code, notes, and snippets.

@channprj
Last active April 11, 2017 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save channprj/a6b221540ddefd19a1adf92879024dc1 to your computer and use it in GitHub Desktop.
Save channprj/a6b221540ddefd19a1adf92879024dc1 to your computer and use it in GitHub Desktop.

Postgresql Cheat Sheet

'SHOW FULL PROCESSLIST;' in postgres

SELECT * FROM pg_stat_activity;

Init auto incremental index

ALTER SEQUENCE check_hrpcs_module_idx_seq RESTART WITH 1;

Export table to CSV file

\COPY tablename TO '<file_path>';
\COPY tablename TO '<file_path>' DELIMITER ';' CSV HEADER;

Import table to CSV file

\COPY tablename from '<file_path>';

Dump

pg_dump -U <USERNAME> --data-only --table=<TABLE> <DB> > <file_name.sql>

Restore

psql -U <USERNAME> <DB> < <file_name.sql>

Query in Shell

psql -U postgres -d <DB> -c "SELECT * FROM <TABLE> WHERE id > -1"

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