about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xtools/conf/etc/rc.d/postgresql16
-rw-r--r--tools/conf/srv/pgsql/data/pg_hba.conf96
-rw-r--r--tools/postgresql.html165
-rw-r--r--tools/scripts/install-postgres.sh16
4 files changed, 203 insertions, 90 deletions
diff --git a/tools/conf/etc/rc.d/postgresql b/tools/conf/etc/rc.d/postgresql
new file mode 100755
index 0000000..5f0762a
--- /dev/null
+++ b/tools/conf/etc/rc.d/postgresql
@@ -0,0 +1,16 @@
+#
+# /etc/rc.d/postgresql: start, stop or restart PostgreSQL server postmaster
+#
+
+PG_DATA=/srv/pgsql/data
+
+case "$1" in
+    start|stop|status|restart|reload)
+        sudo -u postgres pg_ctl -D "$PG_DATA" -l /var/log/postgresql "$1"
+        ;;
+    *)
+        echo "usage: $0 start|stop|restart|reload|status"
+        ;;
+esac
+
+# End of file
diff --git a/tools/conf/srv/pgsql/data/pg_hba.conf b/tools/conf/srv/pgsql/data/pg_hba.conf
new file mode 100644
index 0000000..34587d4
--- /dev/null
+++ b/tools/conf/srv/pgsql/data/pg_hba.conf
@@ -0,0 +1,96 @@
+# PostgreSQL Client Authentication Configuration File
+# ===================================================
+#
+# Refer to the "Client Authentication" section in the PostgreSQL
+# documentation for a complete description of this file.  A short
+# synopsis follows.
+#
+# This file controls: which hosts are allowed to connect, how clients
+# are authenticated, which PostgreSQL user names they can use, which
+# databases they can access.  Records take one of these forms:
+#
+# local      DATABASE  USER  METHOD  [OPTIONS]
+# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
+# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
+# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
+#
+# (The uppercase items must be replaced by actual values.)
+#
+# The first field is the connection type: "local" is a Unix-domain
+# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
+# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
+# plain TCP/IP socket.
+#
+# DATABASE can be "all", "sameuser", "samerole", "replication", a
+# database name, or a comma-separated list thereof. The "all"
+# keyword does not match "replication". Access to replication
+# must be enabled in a separate record (see example below).
+#
+# USER can be "all", a user name, a group name prefixed with "+", or a
+# comma-separated list thereof.  In both the DATABASE and USER fields
+# you can also write a file name prefixed with "@" to include names
+# from a separate file.
+#
+# ADDRESS specifies the set of hosts the record matches.  It can be a
+# host name, or it is made up of an IP address and a CIDR mask that is
+# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
+# specifies the number of significant bits in the mask.  A host name
+# that starts with a dot (.) matches a suffix of the actual host name.
+# Alternatively, you can write an IP address and netmask in separate
+# columns to specify the set of hosts.  Instead of a CIDR-address, you
+# can write "samehost" to match any of the server's own IP addresses,
+# or "samenet" to match any address in any subnet that the server is
+# directly connected to.
+#
+# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
+# "ident", "peer", "pam", "ldap", "radius" or "cert".  Note that
+# "password" sends passwords in clear text; "md5" is preferred since
+# it sends encrypted passwords.
+#
+# OPTIONS are a set of options for the authentication in the format
+# NAME=VALUE.  The available options depend on the different
+# authentication methods -- refer to the "Client Authentication"
+# section in the documentation for a list of which options are
+# available for which authentication methods.
+#
+# Database and user names containing spaces, commas, quotes and other
+# special characters must be quoted.  Quoting one of the keywords
+# "all", "sameuser", "samerole" or "replication" makes the name lose
+# its special character, and just match a database or username with
+# that name.
+#
+# This file is read on server startup and when the postmaster receives
+# a SIGHUP signal.  If you edit the file on a running system, you have
+# to SIGHUP the postmaster for the changes to take effect.  You can
+# use "pg_ctl reload" to do that.
+
+# Put your actual configuration here
+# ----------------------------------
+#
+# If you want to allow non-local connections, you need to add more
+# "host" records.  In that case you will also need to make PostgreSQL
+# listen on a non-local interface via the listen_addresses
+# configuration parameter, or via the -i or -h command line switches.
+
+# CAUTION: Configuring the system for local "trust" authentication
+# allows any local user to connect as any PostgreSQL user, including
+# the database superuser.  If you do not trust all your local users,
+# use another authentication method.
+
+
+# TYPE  DATABASE        USER            ADDRESS                 METHOD
+
+# "local" is for Unix domain socket connections only
+#local   all             all                                     trust
+local   all             postgres                                ident
+# IPv4 local connections:
+#host    all             all             127.0.0.1/32            trust
+hostssl    all             all             127.0.0.1/32          md5
+
+# IPv6 local connections:
+#host    all             all             ::1/128                 trust
+# Allow replication connections from localhost, by a user with the
+# replication privilege.
+#local   replication     postgres                                trust
+#host    replication     postgres        127.0.0.1/32            trust
+#host    replication     postgres        ::1/128                 trust
diff --git a/tools/postgresql.html b/tools/postgresql.html
index e160ae2..b8790e2 100644
--- a/tools/postgresql.html
+++ b/tools/postgresql.html
@@ -11,53 +11,22 @@
         <h1>Postgresql</h1>
 
 
-        <h2 id="install">1.1. Install Postgresql</h2>
+        <h2 id="install">1. Install Postgresql</h2>
 
-        <pre>
-        $ prt-get depinst postgresql
-        </pre>
-
-        <p>Mount Point;</p>
-
-        <pre>
-        # mkdir -p /srv/pgsql
-        # mount /srv/pgsql
-        </pre>
-
-        <p>Create user;</p>
-
-        <pre>
-        # useradd -U -m -d /srv/pgsql -s /bin/false postgres
-        useradd: warning: the home directory already exists.
-        Not copying any file from skel directory into it.
-        </pre>
+        <p>Install postgresql;</p>
 
         <pre>
-        # passwd -l postgres
-        passwd: password expiry information changed.
-        # touch /var/log/pgsql
-        # chown -R postgres:postgres /srv/pgsql /var/log/pgsql
-        # ldconfig /user/lib/postgresql
-		</pre>
-
-        $ sudo -u postgres mkdir -p /srv/pgsql/data
-        # sudo -u postgres touch /srv/pgsql/.psql_history
+        $ prt-get depinst postgresql
         </pre>
 
-        <p>Create /etc/logrotate.d/postgres;</p>
-
         <pre>
-        /var/log/pgsql {
-            weekly
-            compress
-            delaycompress
-            rotate 10
-            notifempty
-            create 660 postgres postgres
-        }
+        # mkdir /srv/pgsql/
+        # touch /var/log/postgresql
+        # chown postgres:postgres /srv/pgsql /var/log/postgresql
+        # sudo -u postgres initdb -D /srv/pgsql/data
         </pre>
 
-        <p>Edit /etc/rc.d/postgresql;</p>
+        <p>Change <a href="conf/etc/rc.d/postgresql">/etc/rc.d/postgresql</a>;</p>
 
         <pre>
         #
@@ -65,25 +34,20 @@
         #
 
         PG_DATA=/srv/pgsql/data
-        PG_HOME=/srv/pgsql
 
         case "$1" in
-        start|stop|status|restart|reload)
-                (cd $PG_HOME && sudo -u postgres pg_ctl -D "$PG_DATA" -l /var/log/pgsql "$1")
-        ;;
-        *)
-        echo "usage: $0 start|stop|restart|reload|status"
-        ;;
+            start|stop|status|restart|reload)
+                sudo -u postgres pg_ctl -D "$PG_DATA" -l /var/log/postgresql "$1"
+                ;;
+            *)
+                echo "usage: $0 start|stop|restart|reload|status"
+                ;;
         esac
 
         # End of file
         </pre>
 
-        <h2 id="config">1.2. Configure Server</h2>
-
-        <pre>
-        # sudo -u postgres initdb -D /srv/pgsql/data
-        </pre>
+        <h2 id="config">2. Configure Server</h2>
 
         <p>Create password for super user;</p>
 
@@ -92,17 +56,9 @@
         $ psql -U postgres
         </pre>
 
-        <p>Edit /pgsql/data/<a href="../conf/srv/pgsql/data/postgresql.conf">postgresql.conf</a>;</p>
-
-        <pre>
-        log_destination = 'syslog' # Can specify multiple destinations
-        syslog_facility='LOCAL0'
-        syslog_ident='postgres'
-        log_connections = on
-        password_encryption=on
-        </pre>
-
-        <p>Edit /srv/pgsql/data/<a href="../conf/srv/pgsql/data/pg_hba.conf">pg_hba.conf</a>;</p>
+        <p>Edit
+        <a href="conf/srv/pgsql/data/pg_hba.conf">/srv/pgsql/data/pg_hba.conf</a>;
+        </p>
 
         <pre>
         # TYPE  DATABASE        USER            ADDRESS                 METHOD
@@ -121,62 +77,89 @@
         #host    replication     postgres        ::1/128                 trust
         </pre>
 
+        <p>Start server and alter postgres password</p>
+
+        <pre>
+        # /etc/rc.d/postgresql start
+        </pre>
+
+        <pre>
+        postgres=# alter user postgres with password 'new_password';
+        </pre>
+
+        <h3 id="syslog">2.1. Configure syslog-ng</h3>
+
         <p><a href="syslog-ng.html">Configure Syslog-ng</a>, check <a href="http://michael.otacoo.com/postgresql-2/postgres-settings-simple-syslog-configuration-with-syslog-ng/">Michael at otacoo</a> article. Example;</p>
 
+        <p>Edit /pgsql/data/<a href="../conf/srv/pgsql/data/postgresql.conf">postgresql.conf</a>;</p>
+
         <pre>
-        destination postgres { file("/var/log/pgsql"); };
-        filter f_postgres { facility(local0); };
-        log { source(s_log); filter(f_postgres); destination(postgres); };
+        log_destination = 'syslog' # Can specify multiple destinations
+        syslog_facility='LOCAL0'
+        syslog_ident='postgres'
+        log_connections = on
+        password_encryption=on
         </pre>
 
-        <p>Start server and alter postgres password</p>
+
+        <p>Create /etc/logrotate.d/postgres;</p>
 
         <pre>
-        # /etc/rc.d/postgresql start
+        /var/log/pgsql {
+            weekly
+            compress
+            delaycompress
+            rotate 10
+            notifempty
+            create 660 postgres postgres
+        }
         </pre>
 
+
         <pre>
-        postgres=# alter user postgres with password 'new_password';
+        destination postgres { file("/var/log/pgsql"); };
+        filter f_postgres { facility(local0); };
+        log { source(s_log); filter(f_postgres); destination(postgres); };
         </pre>
 
-        <h2 id="createuser">1.3. Create User</h2>
+
+        <h2 id="createuser">3. Create User</h2>
 
         <p>Create a new user with createuser command;</p>
 
         <pre>
         $ sudo -u postgres createuser --pwprompt --encrypted \
-        --no-createrole --no-createdb laravel_user
+        --no-createrole --no-createdb flyspray
         Enter password for new user:
         Enter it again:
         </pre>
 
-        <h2 id="createdb">1.4. Create Database</h2>
+        <h2 id="createdb">4. Create Database</h2>
 
         <p>Create a new database for new user with createdb command;</p>
 
         <pre>
         $ sudo -u postgres createdb --template=template0 --encoding=UTF8 \
-        --owner=laravel_user laravel_db
+        --owner=flyspray db_flyspray
         </pre>
 
-        <h2 id="dropdb">1.5. Drop Database</h2>
+        <h2 id="dropdb">5. Drop Database</h2>
 
         <p>Deleting database with dropdb command;</p>
 
         <pre>
-        sudo -u postgres dropdb laravel_db
+        sudo -u postgres dropdb db_flyspray
         </pre>
 
-        <h2 id="dropuser">1.6. Drop User</h2>
+        <h2 id="dropuser">6. Drop User</h2>
 
         <p>Deleting user with dropuser command;</p>
 
         <pre>
-        sudo -u postgres dropuser laravel_user
+        sudo -u postgres dropuser flyspray
         </pre>
 
-
-        <h2 id="psql">1.7. Psql</h2>
+        <h2 id="psql">7. Psql</h2>
 
         <p>Lets check with psql, login with user postgres;</p>
 
@@ -190,7 +173,7 @@
         postgres=# \?
         </pre>
 
-        <h3 id="listdb">Psql - List Databases and Roles</h3>
+        <h3 id="listdb">7.1. List Databases and Roles</h3>
 
         <p>List roles then list databases;</p>
 
@@ -199,39 +182,43 @@
         postgres=# \l
         </pre>
 
-        <h3 id="psqldb">Psql - Create Database</h3>
+        <h3 id="psqldb">7.2. Create Database</h3>
 
         <pre>
-        postgres=# create database laravel_db_ext owner laravel_user encoding 'UTF-8' template template0;
+        postgres=# create database db_flyspray_ext owner flyspray encoding 'UTF-8' template template0;
         </pre>
 
-        <h3 id="droptables">Psql - Drop Tables</h3>
+        <h3 id="droptables">7.3. Drop Tables</h3>
 
         <p>This example assumes that all tables,
         are in public schema. First connect to database and
         list tables;</p>
 
         <pre>
-        postgres=# \c laravel_db
+        postgres=# revoke SELECT on db_flyspray from flyspray;
+        </pre>
+
+        <pre>
+        postgres=# \c db_flyspray
         postgres=# \dt
         </pre>
 
         <p>Drop all tables on public schema and recreate public schema;</p>
 
         <pre>
-        laravel_db=# drop schema public cascade;
-        laravel_db=# create schema public;
+        db_flyspray=# drop schema public cascade;
+        db_flyspray=# create schema public;
         </pre>
 
-        <h3 id="backup">Backup</h3>
+        <h3 id="backup">7.4. Backup</h3>
 
 
         <p>Backup Database</p>
 
-        <h3 id="backup">Restore</h3>
+        <h3 id="backup">7.5. Restore</h3>
 
         <pre>
-        $ psql laravel_db &lt; database_dump
+        $ psql db_flyspray &lt; database_dump
         </pre>
 
         <a href="index.html">Tools Index</a>
@@ -242,7 +229,5 @@
         See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
         for copying conditions.</p>
 
-
-
     </body>
 </html>
diff --git a/tools/scripts/install-postgres.sh b/tools/scripts/install-postgres.sh
new file mode 100644
index 0000000..06666e0
--- /dev/null
+++ b/tools/scripts/install-postgres.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. `dirname $0`/config-install.sh
+
+prt-get depinst postgresql
+
+cp -R $CONF_DIR/etc/rc.d/postgresql /etc/rc.d/
+
+mkdir /srv/pgsql/
+touch /var/log/postgresql
+chown postgres:postgres /srv/pgsql /var/log/postgresql
+
+sudo -u postgres initdb -D /srv/pgsql/data
+
+cp $CONF_DIR/srv/pgsql/data/pg_hba.conf /srv/pgsql/data/
+chown postgres:postgres /srv/pgsql/data/pg_hba.conf