Setting application_name on Postgres/SQLAlchemy

the answer to this is a combination of: http://initd.org/psycopg/docs/module.html#psycopg2.connect Any other connection parameter supported by the client library/server can be passed either in the connection string or as keywords. The PostgreSQL documentation contains the complete list of the supported parameters. Also note that the same parameters can be passed to the client library using environment … Read more

About clustered index in postgres

Note that PostgreSQL uses the term “clustered index” to use something vaguely similar and yet very different to SQL Server. If a particular index has been nominated as the clustering index for a table, then psql’s \d command will indicate the clustered index, e.g., Indexes: “timezone_description_pkey” PRIMARY KEY, btree (timezone) CLUSTER PostgreSQL does not nominate … Read more

PostgreSQL via SSH Tunnel

Your pg_hba.conf appears to permit connections from localhost. The easiest way of causing your SSH tunnel connections to appear from localhost is to make them to localhost. The following SSH command connects to remote.example.com as user “user”, and causes your ssh client to listen on localhost, port 1111/tcp. Any connections made to that port will … Read more

Postgres table column name restrictions?

Here’s a nice table of reserved words in PostgreSQL: http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html It is probably best to simply avoid using those words as table- or column-names. An alternative, however, is to enclose the identifier in double-quotes, e.g.: CREATE TABLE IF NOT EXISTS apiss ( skey TEXT, time INTEGER, “user” TEXT, ip TEXT); Additionally, Postgres reserves system column … Read more

Terminate hung query (idle in transaction)

This is a general PostgreSQL answer, and not specific to Heroku (The simple-stupid answer to this question may be … just restart postgresql. Assuming that’s not desirable or not an option …) Find the PID by running this sql: SELECT pid , query, * from pg_stat_activity WHERE state != ‘idle’ ORDER BY xact_start; (The query … Read more