Skip to content

Instantly share code, notes, and snippets.

🎸
hard as a rock

Christian Castelli chrisvoo

🎸
hard as a rock
Block or report user

Report or block chrisvoo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrisvoo
chrisvoo / pgsql_administration.sh
Last active Oct 6, 2016
psql/pg_dump administration commands
View pgsql_administration.sh
# dump of your database in plain text. It creates tables, views, etc
# for exporting multiple tables only, you can repeat parameter -t
pg_dump --host <IP> --port 5432 --username "myuser" \
--format plain --create --encoding UTF8 -v \
--file "/my/path/file.sql" "db_name"
# or, with short opts and wrapping all SQL statements inside a transaction with automatic ROLLBACK
psql -U postgres -p 5433 --single-transaction -f /my/path/file.sql db_name
# Import of a SQL dump. Be sure to have write permissions in the current directory
@chrisvoo
chrisvoo / pgsql_cheatsheet.sql
Last active Apr 22, 2017
PostgreSQL cheat sheet
View pgsql_cheatsheet.sql
-- QUERIES OPERATIONS
----------------------------------------------------------------------------------
-- KILL ALL sessions FOR A DATABASE
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND pid <> pg_backend_pid();
-- GETTING RUNNING QUERIES, version: 9.2+
You can’t perform that action at this time.