Last active
August 29, 2015 14:05
-
-
Save meganlkm/08655c82c1a8a542da03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- postgres snippets | |
-- show databases owned by a specific user | |
psql -d postgres -c "SELECT datname FROM pg_database JOIN pg_authid ON pg_database.datdba = pg_authid.oid WHERE rolname = 'rolename'" | |
-- see all active sessions | |
SELECT * FROM pg_stat_activity; | |
-- kill sessions | |
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'dbname' AND pid <> pg_backend_pid(); | |
-- Change the database ownership | |
alter database dbname owner to dbuser; | |
-- and do the same for all tables | |
psql -tc "select 'alter table ' || tablename || ' owner to dbuser;' from pg_tables where schemaname not in ('pg_catalog', 'information_schema');" dbname | psql -a dbname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment