33
Steps to Install PostgreSQL Server/client The following steps to install PostgreSql Server on Windows : When the installer appears you can accept all of the default values by clicking the Next button. You will need to enter a password that you will need to access the PostgreSQL server later on. Make sure you remember the password you enter.

Postgre sql run book

Embed Size (px)

DESCRIPTION

Installation on Windows and Linux;Backups on Linux and Windows;Connections between Clients and Servers

Citation preview

Page 1: Postgre sql run book

Steps to Install PostgreSQL Server/clientThe following steps to install PostgreSql Server on Windows :

When the installer appears you can accept all of the default values by clicking the Next button. You will need to enter a password that you will need to access the PostgreSQL server later on. Make sure you remember the password you enter.

Page 2: Postgre sql run book

Here we need to give Password of the Super User. Here Super User is “postgres “.This password is used for while connecting the server we need to give this password.

Page 3: Postgre sql run book

By default Port number the server is 5432

Page 4: Postgre sql run book

After a successful installation you will be prompted to launch Stack Builder. You can uncheck this checkbox and click Finish.

Server Configuration from client (Win) to server (Win)

--In client side we have to add new server config

Page 5: Postgre sql run book

In the "New Server Registration" dialog that appears, enter appropriate values for your server name and PostgreSQL account credentials. Be sure to specify "localhost" for the "Host" field, as you'll be connecting via your SSH tunnel. Click "OK" to connect to your server.

You will be presented with a full view of the databases that your user account has access to.

--Now we need to set client IP address in server config file onpg_hba.config (in Server Machine Win)

Location : C:\Program Files\PostgreSQL\9.2\data\pg_hba.config file

Then,come down end of the file we need to add client ip address on following way.

Add IP Address of win client box

Page 6: Postgre sql run book

--From client side we are getting server details.

In Config file set the particular DB,particular user on server side : (Win(client) to Win(server)) :

Here we connect only particular database,particular user from client side(Win Box).First we need to config file (from server side(win box)) ,open C:/Program files/Postgresql/8.4/data/pg_hda.config file ,in that we add particulat DB,Particular user,IP address (client box(Win)) and save it.After that restart the server.

--- From client side connecting Particular DB,particular user .(In Win Box)C:\Program Files\PostgreSQL\9.2\bin>psql -h 10.65.2.49 -d sample -U u2

From server side(win) add particular DB and user

Page 7: Postgre sql run book

In Config file set the particular DB,particular user from server side : (Win(server) to Win(client)) :

Here we connect only particular database,particular user from client side(Win Box). First we need to config file (from server side(win box)) ,open C:/Program files/Postgresql/8.4/data/pg_hda.config file ,in that we add particulat DB,Particular user,IP address (client box(Win)) and save it.After that restart the server

----From client side connecting Particular DB,particular user .(In Win Box)C:\Program Files\PostgreSQL\9.2\bin>psql -h 10.65.0.141 -d test1 –U test_user

From server side(win) add particular DB and user

Page 8: Postgre sql run book

--Connecting the postgresfromcmd prompt on Windows.

The following Screen are Creating Database in command prompt by using Postgres (Super User).Enter the postgres bin path then give “psql –U postgres “,Here we need to give passwd of superuser Postgres.After login create one sample database called “sample”,after creating a

Page 9: Postgre sql run book

database check wether database is created or not by using \l command,it shows all list of databases.

Here create one sample user called sam_user1 and passwd is same as username.Next we connect the particular database by using user (sam_user1) login .Here ” sample” is the database ;username is sam_user1 .Create a table and insert the values ;and select the table.

--Insert the values in to particular table :

Go to Start -->All Programs -- >PostgreSQL9.2 -- >PgAdminIIIIn Menu barTools ScriptsINSERT Script

Page 10: Postgre sql run book

The Quary window will be coming ,in that we select database and username like below mentiond in red mark.

----- The following screen displays how to take database or schemas backup and restore on cmd prompt(Windows).

Here pg_dump is used for taking the backup utility.Login as a SuperUser and give Database at the end of the line.And mention the backup up location where we have to copy the backup file.Here DB is :sample(from Bkup) ;To Restore DB is :TestDB.

OR

In this screen simple give Restore and backup commands

Here DB name :INFO(From Bkup);To Restore DB is : vv2.

Page 11: Postgre sql run book

OR

Here also give simple Backup asd Restore commands with out “Qautations”

- Creating DB and User priveleges on cmd : (Windows)

--- Create a database

Page 12: Postgre sql run book

C:\program files\Postgresql\version\bin>psql -U postgres Enter passwd for postgre :postgres postgres-# create database postgressvtdb; database created(OR)[prompt]$ created dbname –U user-name -W drop user username;Postgres=# create database dbname;

--To check database is created or not

postgres-# \l (it displays the list of databases)

--- Delete a database

[prompt]$ destroy db dbname;[prompt]$ drop db dbname ;[prompt]$ drop database dbname;

---Create user : Adding New Users

A superuser or the database owner can create users in PostgreSQL. Use the CREATE USER SQL command or the createuser shell script to create users.

Syntax:

CREATE USER username[ WITHSYSID uid| CREATEDB | NOCREATEDB| CREATEUSER | NOCREATEUSER| IN GROUP groupname[, ...]| [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'| VALID UNTIL 'abstime' ]

[prompt] $ create user username with password ‘password’;(OR)Postgres=#CREATE USER username WITH PASSWORD 'password' CREATEDB VALIDUNTIL 'yyyy-mm-dd';

--Manipulating Users :( Altering a User)

In PostgreSQL, each user is identified as an object. It is possible to modify the properties of any user. This process is known as altering a user. Use the ALTER USER command to alter a user. Only superusers can execute this command.

Syntax :

ALTER USER username[ WITHCREATEDB | NOCREATEDB | CREATEUSER |NOCREATEUSER| [ ENCRYPTED | UNENCRYPTED ] PASSWORD 'password'| VALID UNTIL 'abstime';

Postgres=#ALTER USER username NOCREATEDB;Sometimes you may need to change the user's name, in which case the alternate syntax is provided:

ALTER USER oldname RENAME TO newname;

Page 13: Postgre sql run book

The ALTER USER command is used to reset the password and expiry time, if specified, as shown in the following code:

mydatabase=# ALTER USER username WITH PASSWORD ‘password’ VALID UNTIL ‘yyyy-mm-dd’;

-- Delete a user

Only a superuser can remove a user, provided the specified user is not the owner of any database. If the user is the owner of a database, drop the database first and then the user. The alternative is to change the owner of the database in the pg_database table.

[prompt]$ drop user username;

---Group Management :

PostgreSQL enables you to manage multiple users as groups. Groups are a single identity for multiple users with a similar set of rights and privileges. They also exist as database objects and are stored in the system catalog.

To grant a similar set of rights to several individuals, create a group consisting of many individuals. Rights granted to a group apply to all the users with in that group. If you are not sure of the users, first create an empty group and then add or remove users using the ALTER GROUP SQL command. You can specify one or more users while creating a group.

In PostgreSQL, the super user creates and removes groups using the CREATE GROUP and DROP GROUP SQL commands.

--- Creating a Group

You can use the CREATE GROUP SQL command to create a group, using this syntax:

CREATE GROUP groupname [WITH] [SYSID groupid] [USER username [,........]]]

Note : Here, groupname is the name of the group and it must begin with an alphabet and not exceed more than 31 characters.

mydatabase=# CREATE GROUP groupname WITH USER username, anewuser;

---Removing a Group:

To remove a group, use the DROP GROUP SQL command. The syntax for the DROP GROUP SQL command is:

mydatabase=#DROP GROUP groupname;

Here, the groupname identifies the group to be dropped. When you drop a group, the rights and permissions associated with it are retained. If you drop a group by mistake, recreate it with the same name specifying the same SYSID. Since group membership information no longer exists, user names need to be added to the group.

--- Altering a Group

Page 14: Postgre sql run book

Groups are created to manage multiple users with a similar set of permissions. To make changes.

Syntax :

ALTER GROUP groupname{ ADD | DROP } USER username[,.....]

---Adding User to a Group

Use the following code to add a user to an existing group.

mydatabase=# ALTER GROUP groupname ADD USER username, username2;

The above code adds username1 and username2 to the “groupname” group and assigns them the rights and privileges of the group.

--Removing Users from a Group

Use the ALTER command to drop a user, as shown in the following code:

mydatabase=# ALTER GROUP groupname DROP USER username;

The code above drops the user “username” from the “groupname” group.

--Grant priveliges from database to user:

Postgres=# grant all on database postgresvtdb to testuser;postgres=# grant connect on database postgresvtdb to testuser;postgres=# grant priveliges on database postgresvtdb to testuser;

--- Grant privileges: Syntax

Privileges are the rights you grant to a user or group for specific table views or sequence within a database. Each privilege is associated with a special character symbol

GRANT privilege[, ...] ON object [, ...] TO{PUBLIC | GROUP groupname | username }[ WITH GRANT OPTION ];

Postgres=# GRANT UPDATE ON table-name to username;Postgres=# GRANT SELECT ON table-name to username;Postgres=# GRANT INSERT ON table-name to username;Postgres=# GRANT DELETE ON table-name to username;Postgres=# GRANT RULE ON table-name to username;Postgres=# GRANT TRIGGER ON table-name to username;Postgres=# GRANT REFERENCE ON table-name to username;Postgres=# GRANT UPDATE ON table-name to username;Postgres=# GRANT ALL PRIVILEGES ON table-name to public;Postgres=# GRANT SELECT,INSERT ON tablename1, tablename2 TO username1, username2 WITH GRANT OPTION;

The following code shows how to grant all the privileges to a specific user, manager:

mydatabase=# GRANT ALL ON customers, books, publishers TO manager;

Page 15: Postgre sql run book

CHANGE

The code above grants the ALL privileges to the user manager on the tables, customers, books, and publishers in mydatabase.

You can view the privileges granted by specifying the \z command with the name of the table, view, or sequence, as shown in the following code.

mydatabase=# \z publishers

Privileges granted to a group apply to all users within it. The following code shows how to grant privileges to a group

mydatabase=# GRANT SELECT ON customers TO GROUP SALES;CHANGE

The code above grants the SELECT privilege on the database, mydatabase to the group Sales.To view the privileges granted, use the following code.

mydatabase=# \z customers

--Revoke privileges from database to user : Syntax

In PostgreSQL, only the administrator and database owners can define the rights to others for using the database. You can define privileges to other users and groups using the GRANT command. To revoke the privileges granted, use the REVOKE command.

REVOKE privilege [, ...] ON object [, ...] FROM{PUBLIC | GROUP groupname | username };

(i) Revoke insert privilege for the public on table tname : Revoke insert on tname from public;(II) Revoke all privileges from user username on view viewname : Revoke all Privileges on viewname from username;(III) Revoke membership in role admins from username : Revoke admins from username;(IV) Revoke all on tablenames FROM usernames;

The following code shows the REVOKE command given on the GROUP sales to revoke the SELECT privilege ON the table customers.mydatabase=# REVOKE SELECT ON customers FROM GROUP sales;CHANGEUsing Views for Access Control :

You can create and use views for access control. Views display restricted data to the users.A SELECT privilege allows a user to access or view all the information in a table. A view is a restricted version of a table and consists of information that the database owner wants to make available.When creating a view, specify the columns that will be part of it.

Listing: Creation of a View :

mydatabase=# CREATE VIEW stock_view AS SELECT isbn, retail, stock FROM stock;CREATE

Page 16: Postgre sql run book

mydatabase=# GRANT SELECT ON stock_view TO GROUP sales;CHANGE

mydatabase=# \z stockAccess permissions for database "mydatabase"Relation | Access Permission----------------------------------- stock | stock_backup |stock_view|{"=", "manager=arwR", "group sales=r"}

The listing above creates a view called the stock_view, which contains data from the stock table. Privileges are granted to the users in this view and not in the table.Users can access information but view only the information available in the stock_view.

--- Create Tablespace

Create tablespace “Tablespacename” ownername location ‘c:/program files/postgresql/8.3/data/dbs or pg_tblspc’;

Create tablespace tablespacename location ‘mnt/sda1/postgresql/data’;

Create table tablename(I int) tablespace tablespacename;

--- Select default tablespaces

select * from pg_tablespace;

---- Alternatively, use the default_tablespace parameterSET default_tablespace=tablespacename;CREATE TABLE tablename(I int);

---- Renames a current tablespace to a new name

ALTER TABLESPACE tablespacename RENAME TO newtablespacename;

----- To changes the owner of a tablespace to a new owner

ALTER TABLESPACE tablespacename OWNER TO newowner;------ To remove an empty tablespace

DROP TABLESPACE tablespacename;

------ Connect to a particular database

postgres=# \c samplepsql (8.4.2)You are now connected to database "sample".sample=#

---- List all users and their permission levels

Postgres=# \du

Page 17: Postgre sql run book

--- Shows summary information about all tables in the current database

Postgres=# \dt

--- Exit/quit the psql shell

Postgres=# \q or CTRL+d

Installtion PostgreSQL Server/Client on Linux

Note: PostgreSql Server installation should be done through User Postgres

--Login as root user:-

Step 1: Creating the “postgres” User

(1) Create a group called dba [root@INVIRH54DB2 etc]# # groupadd –g 1020 dba

(2) Create a user called “postgres”

[root@INVIRH54DB2 etc]# useradd -g dba -u 888 -d /data1/postgres -m postgres

(3) Change the password of user postgres.

Before installing we need to check the following versions.$ gmake –version$ gcc –version$ gzip –version$ tar –version$ df –k(8 to 15 MB need)

Step 2: Installing the PostgreSQL Source Package (Login as a Postgres User)

--------------> Unpacking the PostgreSQL source package

[postgres@INVIRH54DB2 ~]# cd /data1/postgres/[postgres@INVIRH54DB2 ~]$ gunzip postgresql-8.4.2.tar.gz[postgres@INVIRH54DB2 ~]$ tar -xvf postgresql-8.4.2.tar

Step 3: Configuring the Source Tree (Login as a Postgres user)

--------------> $ use ./configure –help[postgres@INVIRH54DB2 ~]$ cd postgresql-8.4.2[postgres@INVIRH54DB2 postgresql-8.4.2]$ ./configurechecking build system type... x86_64-unknown-linux-gnuchecking whether to build with 64-bit integer date/time support... yeschecking whether NLS is wanted... no“

Page 18: Postgre sql run book

[“]

Step 4: Compiling the Source : Compiling the source with GNU make

[postgres@INVIRH54DB2 postgresql-8.4.2]$ gmakegmake -C doc allgmake[1]: Entering directory /usr/local/src/postgresql-8.4.1/doc'gmake[1]: Nothing to be done for all'.gmake[3]: Entering directory /usr/local/src/postgresql-8.4.1/src/backend/utils'“All of PostgreSQL successfully made. Ready to install.

Step 5: Installing Compiled Programs and Libraries (Login as a root)

[root@INVIRH54DB2 postgresql-8.4.2]# gmake installgmake -C doc installgmake[1]: Entering directory `/data1/postgres/postgresql-8.4.2/doc'mkdir -p -- /usr/local/pgsql/share/doc//htmlmkdir -p -- /usr/local/pgsql/share/man/man1 /usr/local/pgsql/share/man/man7gzip -d -c ./postgres.tar.gz | ( cd /usr/local/pgsql/share/doc//html && /bin/tar xf -)/bin/tar: Read 9728 bytes from –“make[1]: Leaving directory `/data1/postgres/postgresql-8.4.2/config'PostgreSQL installation complete.

Create and initialize the database and invoke the postmaster application. The directory used by the postmaster must be created and access restricted to postgres only. The command used is:

[root@INVIRH54DB2 postgresql-8.4.2]# mkdir /usr/local/pgsql/data[root@INVIRH54DB2 postgresql-8.4.2]# chown postgres /usr/local/pgsql/data

Step 6 : Initializing and Starting PostgreSQL (Login as a postgres user)

Now it's time to execute the initdb command, which will create the cluster. However, you should do so as the postgres user, so change over to that user before proceeding.

The database is initialized when postgres logs on to it. The command initdb initializes the database, which consists of server process, applications, and data files. The command for creating an empty database for postgresis :

--------Initializing the database

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

The files belonging to this database system will be owned by user "postgres".This user must also own the server process.The database cluster will be initialized with locale en_US.UTF-8.The default text search configuration will be set to "english".“Success. You can now start the database server using:/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data (I)

Page 19: Postgre sql run book

Or/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start (II)here -D is the Data

/* Running postmaster in the foreground (Login as a postgres) */

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/dataLOG: database system was shut down at 2012-12-17 11:19:56 ISTLOG: autovacuum launcher startedLOG: database system is ready to accept connections“(OR)

The server process is started after the database is created. The command used is:

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &

/* Running postmaster in the background (we mention /tmp/pgsql.log. in the following command) */

$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /tmp/pgsql.log start

postmaster successfully started

Step 7: Configuring the PostgreSQL SysV Script :

First, change to the directory where you unpacked the PostgreSQL source. In our case, the path to that directory is /usr/local/src/postgresql-8.4.1/. Then, issue a cp command to copy the script from contrib/start-scripts into the init.d directory.Copying the linux script.Installing as service ( service files can be found from source code directory)

(I) go to /installation/startup-scripts (go to installation path like /u01/app/postgres/postgres-8.4.1/contrib/start-scripts/linux..…)

(II) Copy the startup script to the proper location.

/ * Be sure to execute these as the root user */

[root@INVIRH54DB2 postgresql-8.4.2]# cp /data1/postgres/postgresql-8.4.2/contrib/start-scripts/linux /etc/init.d/postgresqlMaking the linux script executable[root@INVIRH54DB2 postgresql-8.4.2]# chmod 755 /etc/init.d/postgresql && cd /etc/init.d/[root@INVIRH54DB2 init.d]# chkconfig --add postgresql[root@INVIRH54DB2 init.d]# chkconfig postgresql on

---Starting PostgreSQL with the SysV script : [root@INVIRH54DB2 init.d]# service postgresql startStarting PostgreSQL: ok

--- Stopping PostgreSQL with the SysV script :

Page 20: Postgre sql run book

[root@INVIRH54DB2 init.d]# service postgresql stopStopping PostgreSQL: server stoppedok

-- How to start, stop and restart PostgreSQL database? (in Linux)

[root@INVIRH54DB2 data]# servicepostgresql stopStopping PostgreSQL: server stoppedok[root@INVIRH54DB2 data]# servicepostgresql startStarting PostgreSQL: ok[root@INVIRH54DB2 data]# servicepostgresql restartRestarting PostgreSQL: server stoppedOk

Step 8: Setting Environment Variables : (Login as a root)

The environment variables that should be set are for the man pages and the bin directory----Set /usr/local/pgsql/bin in system PATH

[root@INVIRH54DB2 init.d]# #PATH=$PATH:/usr/local/pgsql/bin;export PATHNote: You must login to the system after the /etc/profile file has had environment variables added to it in order for your shell to utilize them.(OR)[root@INVIRH54DB2 init.d]# PATH=/usr/local/pgsql/bin:$PATH[root@INVIRH54DB2 init.d]# export PATH

In a default installation, shared libraries will be located in /usr/local/pgsql/lib

/*-----Setting LD_LIBRARY_PATH in a bash shell$ LD_LIBRARY_PATH=/usr/local/pgsql/lib (in root)$ export LD_LIBRARY_PATH (in root)----Setting LD_LIBRARY_PATH in csh and tcsh$ setenv LD_LIBRARY_PATH /usr/local/pgsql/lib (in root)*/

Step 9 : Creating a Sample Database (Login as a Postgres user)

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/createdb sample[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -U postgrespsql (8.4.2)Type "help" for help.

postgres=# \l List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges-----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | sample | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |

Page 21: Postgre sql run book

(5 rows)postgres=# -Accessing a database with psql

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql samplepsql (8.4.2)Type "help" for help.sample=#

---Querying a system table

sample=# SELECT * FROM pg_language; lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | lanvalidator | lanacl----------+----------+---------+--------------+---------------+--------------+-------- internal | 10 | f | f | 0 | 2246 | c | 10 | f | f | 0 | 2247 | sql | 10 | f | t | 0 | 2248 |(3 rows)[postgres@host postgresql-8.4.1]#psql -l (Listing Databases)/*Now you many now administrate the postgres from the user console*/

---Create,insert,select commands on Linux

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -d samplepsql (8.4.2)Type "help" for help.sample=# create table emp(int integer,name character(20));CREATE TABLEsample=# insert into emp(int,name) values(1,'s1');INSERT 0 1sample=# insert into emp(int,name) values(2,'s2');INSERT 0 1sample=# insert into emp(int,name) values(3,'s3');INSERT 0 1sample=# select * from emp; int | name-----+---------------------- 1 | s1 2 | s2 3 | s3(3 rows)sample=#

---Backup and restore on linux (Login as a user postgres)

-----Backup :

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/pg_dump -U postgres sample -f /data1/postgres/table.backup

Page 22: Postgre sql run book

--- Retore :

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -U postgres -d testdb -f /data1/postgres/table.backupSETSETSETSETSETSETSETSETSETCREATE TABLEALTER TABLEREVOKEREVOKEGRANT

Connecting client(Linux) to server(Win) on linux Box

(I) First we need to config client ip address on server side (pg_hda.conf (Win))(II) Once finishing the configration we need restart the server.(III) Once restarts the server, we connect from client to server.(IV) In linux box login as a Postgres user,then give the following command :

[postgres@INVIRH54DB2 ~]$ psql -h windows_server_ip_address -l 

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h 10.65.2.49 –l

Here –l is : list of databases (should return all available databases on the windows server)

- To connect a given DB and given user onclient (Linux) to server (Win) :

Page 23: Postgre sql run book

Here we connect only particular database,particular user from client side(Linux Box).First we need to config file (from server side) ,open C:/Program files/Postgresql/8.4/data/pg_hda.config file ,in that we add particulat DB,Particular user,IP address (client box) and save it.After that restart the server.

In server side config (Win) :

Here we connect particular DB,particular user from client side on linux.

(I) Login as a postgres user

[postgres@INVIRH54DB2 ~]$ psql -h windows_server_ip_address -d name_of_database -U database_user 

Here –h ------Windows_Server_IP_Address-d ---------- Name of the Database-U --------- Name of the Database user[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h 10.65.2.49 -d sample -U test_sample

Page 24: Postgre sql run book

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h 10.65.2.49 -d sample -U test_sample

-- Connecting client (Win) to server (Linux) :

Page 25: Postgre sql run book

(I) First we need to config client ip address on server side (pg_hda.config file)(II) Once finishing the configration we need restart the server.(III) Once restarts the server, we connect the client from server(IV) Hereafter insert the following line in the host-based authentication

file /usr/local/pgsql/data/pg_hba.conf. This file controls which hosts are allowed to connect. And edit the pg_hba.conf file.

(V) And we need to add client IP address like the following screen.

[postgres@INVIRH54DB2 data]$ vi pg_hba.conf

In client side we are getting server Details.

Displaying all server side databases in client side :

Page 26: Postgre sql run book

In client side we need to give the following command :Here only particulat DB and particular User connecting.

--- Connecting Server (Win) to client (Linux) :

Page 27: Postgre sql run book

(I) First we need to config client ip address on server side (pg_hda.config file)(II) Once finishing the configration we need restart the server.(III) Once restarts the server we connect the client from server.

In client side we need to give the following command :

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h 10.65.2.49 -U postgresPassword for user postgres:

- To connect a given DB and given user onServer (Win) to Client (Linux) :

In client side we need to give the following command :

[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h 10.65.2.49 -d sample -U user_sample

Page 28: Postgre sql run book

--How to check whether PostgreSQL server is up and running? (In Linux)

[root@INVIRH54DB2 data]# /etc/init.d/postgresql statuspg_ctl: server is running (PID: 669)/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data"

--- Starting the database server : As root

(from most to least favorite method.Servicepostgresql start (if the database has not already been initialized with initdb,this will be performed by the command)OR/etc/rc.d/init.d/postgresql start(if the database has not already been initialized with initdb,this will be performed by the script)OR/usr/bin/pg_ctl –D /var/lib/pgsql/data –p /usr/bin/postmaster –l logfile start &OR

/usr/bin/postmaster –D /var/lib/pgsql/data &

---Postgresql database default location on Linux :

In file system terms, a database cluster will be a single directory which all data will be stored.We call this the data directory or data area.It is completely up to you where you choose to store your data.There is no default,although locations such as /usr/local/pgsql/data or /var/lib/pgsql/data are popular.

[root@INVIRH54DB2 ~]# ps -ef | greppostgrespostgres 9010 1 0 Dec21 ? 00:00:02 /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data