Skip to content

Instantly share code, notes, and snippets.

@gingray
Last active July 1, 2016 15:35
Show Gist options
  • Save gingray/c732ffad02f642326ae1 to your computer and use it in GitHub Desktop.
Save gingray/c732ffad02f642326ae1 to your computer and use it in GitHub Desktop.
postgresql add by default hstore to template0
psql -d template0 -c 'create extension hstore;'

if you get error like database "template0" is not currently accepting connections try this one solution

UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';

but this solution can cause problem when you you will do pg_upgrade be carefull

get current running queries

SELECT * FROM pg_stat_activity;

stop current running query

SELECT pg_cancel_backend(pid of the postgres process);

alter roles

ALTER ROLE user_role_here WITH LOGIN;
ALTER ROLE user_role_here WITH CREATEDB;

kill all connections to 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();

remove duplicates

DELETE FROM tablename
WHERE id IN (SELECT id
              FROM (SELECT id,
                             ROW_NUMBER() OVER (partition BY column1, column2, column3 ORDER BY id) AS rnum
                     FROM tablename) t
              WHERE t.rnum > 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment