postgre.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Tue, 24 Mar 2015 16:52:00 +0200
changeset 1701 6163ba5907d4
parent 1700 f987c277f760
child 1702 d2b977ccbf4f
permissions -rw-r--r--
To switch databases.

.. -*- coding: utf-8; -*-
.. include:: HEADER.rst

==========
 Postgre.
==========
.. contents::

Installing on Debian.
=====================

Install and create new user and database::

  $ sudo apt-get install postgresql postgresql-client
  $ sudo su - postgres
  postgres=# CREATE USER "mypguser" WITH PASSWORD 'mypguserpass';
  postgres=# CREATE DATABASE "mypgdatabase" OWNER "mypguser";
  postgres=# \q

Connect as user ``mypguser`` to new database::

  $ su - mypguser
  $ psql mypgdatabase

..

  https://wiki.debian.org/PostgreSql
    Debian wiki instructions.

List databases, schemas and tables.
===================================

Default database is ``postgres``.

To list databases::

  => \l

To switch databases::

  => \connect NAME

Schemas::

  => select schema_name from information_schema.schemata;
  => select nspname from pg_catalog.pg_namespace;
  => \dn *

To list all tables in the current database::

  => \dt

Using psql client.
==================

Using password file ``~/.pgpass``::

  # comment
  hostname:port:database:username:password
  hostname:port:*:username:password
  hostname:*:*:username:password

Connect by::

  $ psql -U $USER -h $HOST  $SCHEMA