You are here: Home / Debian GNU/Linux / Servers / Databases / Ease PostgreSQL server administration with pgsql-tools

Ease PostgreSQL server administration with pgsql-tools

by Pierre-Yves Landuré last modified Jun 04, 2014 03:07

pgsql-tools is a script I wrote with the goal to ease and automate the regular administration tasks of a PostgreSQL server. This howto describe howto to install and use it.

This howto is tested on :

  • Debian 6.0 Squeeze
  • Debian 7.0 Wheezy

Prerequisites

This howto recommands:

Installation

Install the PostgreSQL client software and the password generation tool apg :

command apt-get install postgresql-client apg

Install the pgsql-tools script:

command wget "https://raw.github.com/biapy/howto.biapy.com/master/postgresql/pgsql-tools" \
    --quiet --no-check-certificate --output-document="/usr/bin/pgsql-tools"
command chmod +x "/usr/bin/pgsql-tools"

Note : This tool is improved on a regular basis.

Presentation of pgsql-tools

Naming convention

Here is a database naming convention proposal:

The database name "ttrss_rss.domain.com" is decomposed in:

  • ttrss_ : hosted application code (here, Tiny Tiny RSS). Allow to group databases by application in PHPPgAdmin.
  • rss.domain.com : Domain name where is hosted the application making use of the database.

The PostgreSQL user for the database "ttrss_rss.domain.com" is "t_rss.domain.com" where:

  • t_ : First letter of the application code (here t_ is the first letter of ttrss_).
  • rss.domain.com : Domain name where is hosted the application making use of the database.

pgsql-tools usage

Create the "MY_BASE" database with the "my_base" user :

# pgsql-tools --create="MY_BASE"

Create the "MY_BASE" with access allowed from host1 and host2 on the network (in addition to localhost) :

# pgsql-tools --host="host1" --host="host2" --create="MY_BASE"

Create a user without access rights (for monitoring use (Nagios)) :

# pgsql-tools --adduser="my_user"

Delete a user :

# pgsql-tools --deluser="my_user"

Drop all tables of the "MY_BASE" database :

# pgsql-tools --empty="MY_BASE"

Drop a database and its dedicated user :

# pgsql-tools --drop="MY_BASE"

Get help on advanced usage of the tool :

# pgsql-tools --help

Thanks