Postgre sql run book


Published on

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

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Postgre sql run book

  1. 1. 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 Nextbutton. You will need to enter a password that you will need to access the PostgreSQL serverlater on. Make sure you remember the password you enter.
  2. 2. Here we need to give Password of the Super User. Here Super User is “postgres “.Thispassword is used for while connecting the server we need to give this password.
  3. 3. By default Port number the server is 5432
  4. 4. After a successful installation you will be prompted to launch Stack Builder. You can uncheckthis checkbox and click Finish.Server Configuration from client (Win) to server (Win)--In client side we have to add new server config
  5. 5. In the "New Server Registration" dialog that appears, enter appropriate values for yourserver name and PostgreSQL account credentials. Be sure to specify "localhost" for the "Host"field, as youll 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 ServerMachine Win)Location : C:Program FilesPostgreSQL9.2datapg_hba.config fileThen,come down end of the file we need to add client ip address on following way. Add IP Address of win client box
  6. 6. --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:/Programfiles/Postgresql/8.4/data/pg_hda.config file ,in that we add particulat DB,Particular user,IPaddress (client box(Win)) and save it.After that restart the server. From server side(win) add particular DB and user
  7. 7. --- From client side connecting Particular DB,particular user .(In Win Box)C:Program FilesPostgreSQL9.2bin>psql -h -d sample -U u2In 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:/Programfiles/Postgresql/8.4/data/pg_hda.config file ,in that we add particulat DB,Particular user,IPaddress (client box(Win)) and save it.After that restart the server From server side(win) add particular DB and user
  8. 8. ----From client side connecting Particular DB,particular user .(In Win Box)C:Program FilesPostgreSQL9.2bin>psql -h -d test1 –U test_user--Connecting the postgresfromcmd prompt on Windows.
  9. 9. The following Screen are Creating Database in command prompt by using Postgres (SuperUser).Enter the postgres bin path then give “psql –U postgres “,Here we need to give passwdof superuser Postgres.After login create one sample database called “sample”,after creating adatabase check wether database is created or not by using l command,it shows all list ofdatabases.Here create one sample user called sam_user1 and passwd is same as username.Next weconnect the particular database by using user (sam_user1) login .Here ” sample” is thedatabase ;username is sam_user1 .Create a table and insert the values ;and select the table.
  10. 10. --Insert the values in to particular table :Go to Start -->All Programs -- >PostgreSQL9.2 -- >PgAdminIIIIn Menu barTools ScriptsINSERT ScriptThe Quary window will be coming ,in that we select database and username like belowmentiond in red mark.----- The following screen displays how to take database or schemas backup andrestore on cmd prompt(Windows).Here pg_dump is used for taking the backup utility.Login as a SuperUser and give Databaseat the end of the line.And mention the backup up location where we have to copy the backupfile.Here DB is :sample(from Bkup) ;To Restore DB is :TestDB.OR
  11. 11. In this screen simple give Restore and backup commandsHere DB name :INFO(From Bkup);To Restore DB is : vv2.ORHere also give simple Backup asd Restore commands with out “Qautations”
  12. 12. -Creating DB and User priveleges on cmd : (Windows)--- Create a database C:program filesPostgresqlversionbin>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 notpostgres-# 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 UsersA superuser or the database owner can create users in PostgreSQL. Use the CREATEUSER 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 ofany user. This process is known as altering a user. Use the ALTER USER command to alter auser. 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;
  13. 13. Sometimes you may need to change the users name, in which case the alternate syntax isprovided:ALTER USER oldname RENAME TO newname;The ALTER USER command is used to reset the password and expiry time, if specified, asshown in the following code:mydatabase=# ALTER USER username WITH PASSWORD „password‟ VALID UNTIL „yyyy-mm-dd‟;-- Delete a userOnly a superuser can remove a user, provided the specified user is not the owner of anydatabase. 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 formultiple users with a similar set of rights and privileges. They also exist as database objectsand are stored in the system catalog.To grant a similar set of rights to several individuals, create a group consisting of manyindividuals. Rights granted to a group apply to all the users with in that group. If you are notsure of the users, first create an empty group and then add or remove users using the ALTERGROUP 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 andDROP GROUP SQL commands.--- Creating a GroupYou 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 andnot 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 GROUPSQL command is:mydatabase=#DROP GROUP groupname;
  14. 14. Here, the groupname identifies the group to be dropped. When you drop a group, the rightsand permissions associated with it are retained. If you drop a group by mistake, recreate itwith the same name specifying the same SYSID. Since group membership information nolonger exists, user names need to be added to the group.--- Altering a GroupGroups are created to manage multiple users with a similar set of permissions. To makechanges.Syntax :ALTER GROUP groupname{ ADD | DROP } USER username[,.....]---Adding User to a GroupUse 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 assignsthem the rights and privileges of the group.--Removing Users from a GroupUse 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: SyntaxPrivileges are the rights you grant to a user or group for specific table views or sequencewithin a database. Each privilege is associated with a special character symbolGRANT privilege[, ...] ON object [, ...] TO{PUBLIC | GROUP groupname | username }[ WITHGRANT 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;
  15. 15. 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, username2WITH 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;CHANGEThe 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 thetable, view, or sequence, as shown in the following code.mydatabase=# z publishersPrivileges granted to a group apply to all users within it. The following code shows how togrant privileges to a groupmydatabase=# GRANT SELECT ON customers TO GROUP SALES;CHANGEThe code above grants the SELECT privilege on the database, mydatabase to the groupSales.To view the privileges granted, use the following code.mydatabase=# z customers--Revoke privileges from database to user : SyntaxIn PostgreSQL, only the administrator and database owners can define the rights to othersfor using the database. You can define privileges to other users and groups using the GRANTcommand. 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 theSELECT privilege ON the table customers.mydatabase=# REVOKE SELECT ON customers FROM GROUP sales;CHANGE
  16. 16. Using 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 arestricted version of a table and consists of information that the database owner wants tomake 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;CREATEmydatabase=# GRANT SELECT ON stock_view TO GROUP sales;CHANGEmydatabase=# 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 stocktable. 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 TablespaceCreate tablespace “Tablespacename” ownername location „c:/programfiles/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 tablespacesselect * from pg_tablespace;---- Alternatively, use the default_tablespace parameterSET default_tablespace=tablespacename;CREATE TABLE tablename(I int);---- Renames a current tablespace to a new nameALTER TABLESPACE tablespacename RENAME TO newtablespacename;----- To changes the owner of a tablespace to a new ownerALTER TABLESPACE tablespacename OWNER TO newowner;
  17. 17. ------ To remove an empty tablespaceDROP TABLESPACE tablespacename;------ Connect to a particular databasepostgres=# c samplepsql (8.4.2)You are now connected to database "sample".sample=#---- List all users and their permission levelsPostgres=# du--- Shows summary information about all tables in the current databasePostgres=# dt--- Exit/quit the psql shellPostgres=# q or CTRL+d Installtion PostgreSQL Server/Client on LinuxNote: 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)
  18. 18. --------------> 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.tarStep 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“[“]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/docgmake[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/docmkdir -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/tarxf -)/bin/tar: Read 9728 bytes from –“make[1]: Leaving directory `/data1/postgres/postgresql-8.4.2/configPostgreSQL installation complete.Create and initialize the database and invoke the postmaster application. The directory usedby the postmaster must be created and access restricted to postgres only. The commandused is:[root@INVIRH54DB2 postgresql-8.4.2]# mkdir /usr/local/pgsql/data[root@INVIRH54DB2 postgresql-8.4.2]# chown postgres /usr/local/pgsql/dataStep 6 : Initializing and Starting PostgreSQL (Login as a postgres user)
  19. 19. Now its time to execute the initdb command, which will create the cluster. However, youshould 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 thedatabase, which consists of server process, applications, and data files. The command forcreating an empty database for postgresis :--------Initializing the database[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/dataThe 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)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 followingcommand) */$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /tmp/pgsql.log startpostmaster successfully startedStep 7: Configuring the PostgreSQL SysV Script :First, change to the directory where you unpacked the PostgreSQL source. In our case, thepath to that directory is /usr/local/src/postgresql-8.4.1/. Then, issue a cp command to copythe script from contrib/start-scripts into the init.d directory.
  20. 20. Copying the linux script.Installing as service ( service files can be found from source codedirectory) (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 :[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 stoppedOkStep 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 variablesadded 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 PATHIn a default installation, shared libraries will be located in /usr/local/pgsql/lib
  21. 21. /*-----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 |(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 tablesample=# 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 TABLE
  22. 22. sample=# 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--- Retore :[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -U postgres -d testdb -f/data1/postgres/table.backupSETSETSETSETSETSETSETSETSETCREATE TABLEALTER TABLEREVOKEREVOKEGRANTConnecting 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.
  23. 23. (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 –lHere –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) :Here we connect only particular database,particular user from client side(Linux Box).First we need to config file (from server side) ,open C:/Programfiles/Postgresql/8.4/data/pg_hda.config file ,in that we add particulat DB,Particular user,IPaddress (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.
  24. 24. (I) Login as a postgres user[postgres@INVIRH54DB2 ~]$ psql -h windows_server_ip_address -d name_of_database -Udatabase_userHere –h ------Windows_Server_IP_Address-d ---------- Name of the Database-U --------- Name of the Database user[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h -d sample -Utest_sample[postgres@INVIRH54DB2 ~]$ /usr/local/pgsql/bin/psql -h -d sample -Utest_sample
  25. 25. --Connecting client (Win) to server (Linux) : (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.confIn client side we are getting server Details.
  26. 26. Displaying all server side databases in client side :
  27. 27. In client side we need to give the following command :Here only particulat DB and particular User connecting. ---Connecting Server (Win) to client (Linux) : (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 -U postgresPassword for user postgres:
  28. 28. -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 -d sample -Uuser_sample --How to check whether PostgreSQL server is up and running? (In Linux) [root@INVIRH54DB2 data]# /etc/init.d/postgresql status pg_ctl: server is running (PID: 669) /usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data"
  29. 29. --- Starting the database server : As root(from most to least favorite method.Servicepostgresql start (if the database has not alreadybeen 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 thescript)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 tostore 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