RPM Installation for PostgreSQL 9.2+

BigSQL provides PostgreSQL 9.2 thru 9.5 RPM packages for an easy installation experience on Redhat/CentOS 6+. This tutorial explains how to install and configure PostgreSQL using BigSQL's rpm packages.

Table of Contents

1. Installation Steps
2. Configure and initializing PostgreSQL Server
3. Using the database
    3.1 Setting the Environment
    3.2 Default database
    3.3 Default username
    3.4 Default password
    3.5 Change the default password
    3.6 Forgot my password!
4. Uninstalling PostgreSQL

 

Installation Steps

The installation of PostgreSQL 9.x server is very easy.

1. Download and save RPM package from http://bigsql.org.

2. Install the RPM package as root


$ sudo yum localinstall postgresql-9.6.2-2-x64-bigsql.rpm

PostgreSQL is cleanly installed to the "/opt/postgresql/pg9x" directory without changing any other shared libraries on your system. All the libraries that PostgreSQL uses are in the "/opt/postgresql/pg9x/lib" directory to minimize the chances of conflicts and other incompatibilities. You can specify --prefix path to rpm to relocate the package to a location of your choice.

3. You may optionally perform step #1 & #2 in one step with a command such as.


$ sudo yum install http://oscg-downloads.s3.amazonaws.com/packages/postgresql-9.6.2-2-x64-bigsql.rpm

Configure and initializing PostgreSQL Server

BigSQL's server control script makes it very easy to configure the PostgreSQL server. The 'start' command will attempt to initialize the server on its first usage (technically in the absence of data directory).

Enter following command in your shell prompt (as root user)


$ /etc/init.d/postgresql-9x start
You will be prompted to provide database server port, superuser password and server startup options. You can either press for default values, or you can provide your own customized inputs. Following the inputs, the database cluster will be initialized and server will be started.

$ /etc/init.d/postgresql-9x start
  PostgreSQL 9.x Configuration
  ---------------------------------
  This will initialize PostgreSQL database cluster. The following
  questions will determine the database server port, superuser password
  and to start server on system boot. Press  to accept defaults.

  Specify PostgreSQL server port [5432]:

  Specify superuser password [password]:
  Do you want PostgreSQL server to be started on boot (y/n) [y]:

  useradd: warning: the home directory already exists.
  Not copying any file from skel directory into it.
  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".

  fixing permissions on existing directory /opt/postgresql/pg9x/data ... ok
  creating subdirectories ... ok
  selecting default max_connections ... 100
  selecting default shared_buffers ... 32MB
  creating configuration files ... ok
  creating template1 database in /opt/postgresql/pg9x/data/base/1 ... ok
  initializing pg_authid ... ok
  setting password ... ok
  initializing dependencies ... ok
  creating system views ... ok
  loading system objects descriptions ... ok
  creating conversions ... ok
  creating dictionaries ... ok
  setting privileges on built-in objects ... ok
  creating information schema ... ok
  loading PL/pgSQL server-side language ... ok
  vacuuming database template1 ... ok
  copying template1 to template0 ... ok
  copying template1 to postgres ... ok

  Success. You can now start the database server using:

      /opt/postgresql/pg9x/bin/postgres -D /opt/postgresql/pg9x/data
  or
      /opt/postgresql/pg9x/bin/pg_ctl -D /opt/postgresql/pg9x/data -l logfile start

  Configuring PostgreSQL server startup scripts
  Starting PostgreSQL 9.x:
  waiting for server to start.... done
  server started
  PostgreSQL 9.x started successfully

Using the Database

To load this postgres into your environment, source the env file:

$ . /opt/postgresql/pg9x/pg9x.env

The server can now be controlled by either using service command and/or by calling the script directly:


$ service postgresql-9x status
  pg_ctl: server is running (PID: 3291)
  /opt/postgresql/pg9x/bin/postgres "-D" "/opt/postgresql/pg9x/data"

$ /etc/init.d/postgresql-9x status
  pg_ctl: server is running (PID: 3291)
  /opt/postgresql/pg9x/bin/postgres "-D" "/opt/postgresql/pg9x/data"

The server is controlled by postgres operating system user, which will be created (as a locked account) by the configuration script if it does not already exists. Using the database

After installation, using the database is simple:


$ /opt/postgresql/pg9x/bin/psql -U postgres -d postgres
  Password:
  psql (9.x)
  Type "help" for help.

  postgres=#

Setting the Environment

The BigSQL's RPMs do not do anything to your system environment in order to prevent conflicts with other software. If you wish to load the environment for this install, you can use the included env file:

$ . /opt/postgresql/pg9x/pg9x.env
$ psql
  Password:
  psql (9.x)
  Type "help" for help.

  postgres=#
This will load:

  * PGHOME
  * PGDATA
  * PATH
  * LD_LIBRARY_PATH
  * PGUSER
  * PGDATABASE
  * PGPORT

Default database

The default database created at initialization time is: postgres

Default username

The default superuser created at initialization time is: postgres

Default password

The default password (unless you set it at initialization time) is: password

Change the default password

To change the default password, you first need to login to the database with your current password:

$ /opt/postgresql/pg9x/bin/psql -U postgres -d postgres
  Password:
  psql (9.x)
  Type "help" for help.

  postgres=#
Now, change the password for the postgres user:

  postgres=# ALTER USER postgres WITH PASSWORD 'newpasswordgoeshere';
  ALTER ROLE
  postgres=#
Now your password is changed.

Forgot my password!

If you've forgotten your password, that's no problem. Here's the reset process: Become the root or postgres user. (Note: postgres might be locked, in which case you must use root account - or unlock postgres account) Edit the pg_hba.conf (host based access) file using your favorite editor

$ su -c "vi /opt/postgresql/pg9x/data/pg_hba.conf"
Change highlighted line

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
by changing connection method from md5 to trust:

# TYPE  DATABASE        USER            CIDR-ADDRESS            METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
Save your changes

Command postgres to re-read it's config file (either as root or postgres user)


$ /etc/init.d/postgresql-9x reload
  Reloading PostgreSQL 9.x:
  server signaled
Switch to normal user and login to the database (you will not be prompted for password).

$ . /opt/postgresql/pg9x/pg9x.env
$ psql
  psql (9.x)
  Type "help" for help.

  postgres=#
Change the password (as described in previous section)

Edit the pg_hba.conf (host based access) file and change trust back to md5 and reload the server.

Uninstalling PostgreSQL Server

The uninstallation of PostgreSQL server can be performed as follows:

$ su -c "rpm -e postgresql9x"

  Attempting to stop server...
  Stopping PostgreSQL 9.x:
  waiting for server to shut down.... done
  server stopped
  Attempting to update server startup status...
  Uninstallation complete.
Note that the data folder is not deleted after uninstallation.