homesourcenvt

PostgreSQL

Overview

Common Tasks

Connecting:

psql -h localhost -U username databasename

See running queries:

SELECT * FROM pg_stat_activity;
-- Cancel
SELECT pg_cancel_backend(PID);
-- Kill the hard way
SELECT pg_terminate_backend(PID);

Dump tables:

pg_dump -t 'aschema.atable' --schema-only database-name

Create users and databases:

CREATE DATABASE db_name;
CREATE USER user_name WITH ENCRYPTED PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE db_name TO user_name;

Resources