Saturday, January 16, 2016

Postgres

* postgres
- postgres
  > Client Installation
 sudo apt-get install postgresql-client
 psql -h server.domain.org database user
 SELECT * FROM table WHERE 1;

- To install the server locally use the command line and type:
  apt-cache search postgres
  ...

- pgadmin3
sudo apt-get install pgadmin3

- Basic Server Setup

: this connects as a role with same name as the local user,
: i.e. "postgres", to the database called "postgres" (1st argument to psql).

sudo -u postgres psql postgres

Set a password for the "postgres" database role using the command:
\password postgres


sudo -u postgres psql postgres -h localhost
ALTER USER USER_ME WITH PASSWORD 'MY_PASS_IS';


cd /usr/share/postgresql/9.4/extension


- Create database
 To create the first database, which we will call "mydb", simply type:
 sudo -u postgres createdb mydb


 > Install Server Instrumentation (for PgAdmin) for Postgresql 8.4 or 9.3

PgAdmin requires the installation of an add-on for full
functionality. The "adminpack" addon, which it calls Server
Instrumentation, is part of postgresql-contrib, so you must install
that package if you haven't already:

sudo apt-get install postgresql-contrib

  Then to activate the extension, for ""Postgresql 8.4"", run the adminpack.sql script, simply type:
 sudo -u postgres psql < /usr/share/postgresql/8.4/contrib/adminpack.sql

For "Postgresql 9.3"+ install the adminpack "extension" in the "postgres" database:
 sudo -u postgres psql
 CREATE EXTENSION adminpack;

 sudo -u postgres psql < /usr/share/postgresql/9.4/extension/adminpack--1.0.sql

- Alternative Server Setup

 sudo -u postgres createuser --superuser $USER
 sudo -u postgres psql
 postgres=# \password $USER
 sudo -u postgres createdb $USER
 psql
 create database amarokdb;
 pgadmin3
 sudo vi /etc/postgresql/9.4/main/pg_hba.conf

# Database administrative login by Unix domain socket
local   all             postgres                                peer
to
# Database administrative login by Unix domain socket
local   all             postgres                                md5

sudo /etc/init.d/postgresql reload

cd /etc/postgresql/9.4/main/

$ sudo vi pg_hba.conf
# "local" is for Unix domain socket connections only
#local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
#
# TYPE  DATABASE    USER        IP-ADDRESS        IP-MASK           METHOD
host    all             all             10.10.50.0    255.255.255.0      md5


$ sudo postgresql.conf
add
  listen_addresses = '*'

then
sudo /etc/init.d/postgresql reload


To create a database with a user that have full rights on the database, use the following command:

sudo -u postgres createuser -D -A -P myuser
sudo -u postgres createdb -O myuser mydb

sudo /etc/init.d/postgresql reload
sudo /etc/init.d/postgresql restart

# "local" is for Unix domain socket connections only
# local   all             all            trust
#
# IPv4 local connections:
#host    all             all            127.0.0.1/32         md5
host    all             all             0.0.0.0/0            md5
host    emacsdb         USER_ME             0.0.0.0/0            md5
host    USER_ME             USER_ME             0.0.0.0/0            md5
# host all all ::1/128 md5 host all postgres 127.0.0.1/32 md5
#
# TYPE  DATABASE    USER        IP-ADDRESS        IP-MASK           METHOD
#host    all             all             10.10.50.0    255.255.255.0      md5


- pgmodeler
http://sourceforge.net/projects/pgmodeler/files/latest/download

No comments:

Pranten

 Pranten