Category Archives: postgres

Unable to load psycopg2 on Mac OSX El Capitan

I upgraded to El Capitan today and of course had to reinstall homebrew and all my python and development tools. I went to try to run a django app on my machine and kept getting this error: django.core.exceptions.ImproperlyConfigured: Error loading … Continue reading

Posted in Mac OS X, postgres, python | Comments Off on Unable to load psycopg2 on Mac OSX El Capitan

How to fix all sequences in postgres 9.x

— select table_name || ‘_’ || column_name || ‘_seq’, reset_sequence(table_name, column_name, table_name || ‘_’ || column_name || ‘_seq’) from information_schema.columns where column_default like ‘nextval%’; — Function: reset_sequence(text, text) — DROP FUNCTION reset_sequence(text, text); CREATE OR REPLACE FUNCTION reset_sequence(tablename text, columnname … Continue reading

Posted in Linux, postgres | Comments Off on How to fix all sequences in postgres 9.x

How to fix postgres sequences that are causing integrity errors.

Save this to a sql file: SELECT ‘SELECT SETVAL(‘ ||quote_literal(quote_ident(S.relname))|| ‘, MAX(‘ ||quote_ident(C.attname)|| ‘)+1) FROM ‘ ||quote_ident(T.relname)|| ‘;’ FROM pg_class AS S, pg_depend AS D, pg_class AS T, pg_attribute AS C WHERE S.relkind = ‘S’ AND S.oid = D.objid AND … Continue reading

Posted in postgres | Comments Off on How to fix postgres sequences that are causing integrity errors.

How to see currently executing queries in postgres 9.2

SELECT query,xact_start,query_start FROM pg_stat_activity;

Posted in postgres | Comments Off on How to see currently executing queries in postgres 9.2

Create superuser(root) in postgres database

I always forget the exact syntax for this so I am posting it here. It’s easy when you know how: CREATE USER root WITH PASSWORD ‘My.g00d.Pa55word’; ALTER USER root WITH SUPERUSER; Also make sure that your ip is allowed in … Continue reading

Posted in postgres | Comments Off on Create superuser(root) in postgres database