postgres import export

Export

pg_dump -c -h 127.0.0.1 -U linkin –column-inserts linkin > dump.sql

IMPORT

in psql:
REVOKE CONNECT ON DATABASE linkin FROM public;

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = ‘linkin’;

drop database linkin;
CREATE DATABASE linkin;
GRANT ALL privileges ON DATABASE linkin TO linkin;

 

in terminal:
psql –file=dump.sql –host=127.0.0.1 –port=5432 –username=linkin –dbname=linkin

Advertisements

Simple setup postgres db for django

sudo apt-get update
sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib
sudo su – postgres
psql
CREATE DATABASE uweb;
CREATE USER django WITH PASSWORD ‘django’;
ALTER ROLE django SET client_encoding TO ‘utf8’;
ALTER ROLE django SET default_transaction_isolation TO ‘read committed’;
ALTER ROLE django SET timezone TO ‘UTC’;
GRANT ALL PRIVILEGES ON DATABASE uweb TO django;