PostgreSQL – how to run VACUUM from code outside transaction block?

After more searching I have discovered the isolation_level property of the psycopg2 connection object. It turns out that changing this to 0 will move you out of a transaction block. Changing the vacuum method of the above class to the following solves it. Note that I also set the isolation level back to what it … Read more

Improving Postgres psycopg2 query performance for Python to the same level of Java’s JDBC driver

This is not an answer out of the box, with all client/db stuff you may need to do some work to determine exactly what is amiss backup postgresql.conf changing log_min_duration_statement to 0 log_destination = ‘csvlog’ # Valid values are combinations of logging_collector = on # Enable capturing of stderr and csvlog log_directory = ‘pg_log’ # … Read more

Creating a postgresql DB using psycopg2

PostgreSQL’s client connects to a database named after the user by default. This is why you get the error FATAL: database “nishant” does not exist. You can connect to the default system database postgres and then issue your query to create the new database. con = connect(dbname=”postgres”, user=”nishant”, host=”localhost”, password=’everything’) Make sure your nishant user … Read more

connect to a DB using psycopg2 without password

Surprisingly, the answer is to not specify a host at all. If you do this, DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’, ‘NAME’: ‘mwt’, } } Then psycopg2 will connect using a Unix socket in the same manner as psql. When you specify a HOST, psycopg2 will connect with TCP/IP, which requires a password.

sqlalchemy.exc.ArgumentError: Can’t load plugin: sqlalchemy.dialects:driver

Here’s how to produce an error like that: >>> from sqlalchemy import * >>> create_engine(“driver://”) Traceback (most recent call last): … etc sqlalchemy.exc.ArgumentError: Can’t load plugin: sqlalchemy.dialects:driver so I’d say you aren’t actually using the postgresql URL you think you are – you probably are calling upon a default-generated alembic.ini somewhere.

Can’t connect the postgreSQL with psycopg2

Your libpq, which is used by psycopg2 expects Postgres socket to be in /var/run/postgresql/ but when you install Postgres from source it is by default it in /tmp/. Check if there is a file /tmp/.s.PGSQL.5432 instead of /var/run/postgresql/.s.PGSQL.5432. Try: conn=psycopg2.connect( database=”mydb”, user=”postgres”, host=”/tmp/”, password=”123″ )

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)