190 Commits

Author SHA1 Message Date
Sameer Naik 197d53e0a1 release 9.4-11 2015-12-13 14:55:54 +05:30
Sameer Naik 88208071b0 dockerfile: upgrade to sameersbn/ubuntu:14.04.20151213 2015-12-13 14:55:20 +05:30
Sameer Naik 38dc995884 added PG_PASSWORD variable to specify password for postgres user
Refer #43
2015-12-11 15:33:59 +05:30
Sameer Naik 116b158c1a release 9.4-10 2015-12-09 22:34:11 +05:30
Sameer Naik 60a249dd7d ensure required defaults are set at every start 2015-12-09 22:33:39 +05:30
Sameer Naik 490f33c05c release 9.4-9 2015-12-05 10:09:23 +05:30
Sameer Naik c1cce0328c disable trigger_file option from recovery.conf
Triggering of a slave to stop replication and enable writing works.
However if a second slave (with data persistence) is reconfigured to
use the first slave (triggered) as the master, the second slave cannot
replicate the data.

At the moment the only way to convert a slave to a master is to stop it
and start it as a master in which case the above issue is not seen.

To avoid users from trying to trigger a slave, we removed the config
altogether until the issue can be resolved.
2015-11-30 11:57:44 +05:30
Sameer Naik ba9d02ecb3 escape & characters in set_postgresql_param 2015-11-29 19:06:10 +05:30
Sameer Naik ee497d68d0 sed variable expansion works by default when double quotes are used 2015-11-29 19:05:08 +05:30
Sameer Naik 8572e6bc77 readme: fixed typo 2015-11-29 11:52:47 +05:30
Sameer Naik cdad6abd5a print value being set in recovery.conf 2015-11-29 11:46:03 +05:30
Sameer Naik d0904a4ca1 set default values of REPLICATION_PORT and REPLICATION_SSLMODE in env-defaults 2015-11-29 11:43:44 +05:30
Sameer Naik 3a838eaa69 readme: fixed typo 2015-11-28 22:23:29 +05:30
Sameer Naik ce64f22779 readme: slave can be restarted to continue as a regular read/write instance 2015-11-28 22:21:17 +05:30
Sameer Naik d92102d951 added DEBUG option to enable bash debugging 2015-11-28 21:19:42 +05:30
Sameer Naik a1ca18b780 recovery.conf can exist only on a slave node
It's existence otherwise cause issues while replication users, as such
the `configure_recovery` function is promoted higher in the
initialization sequence.
2015-11-28 21:18:16 +05:30
Sameer Naik 22c969c88c removed launch sequence from functions import 2015-11-28 14:51:18 +05:30
Sameer Naik 8458c2a3ca user and database can only be created on the master node 2015-11-28 14:22:46 +05:30
Sameer Naik e6dff6ef93 readme: --env consistency 2015-11-28 13:48:23 +05:30
Sameer Naik edee0f1ce7 removed locale setting entry from TOC 2015-11-28 13:15:55 +05:30
Sameer Naik 1f87e4aa1b removed PG_LOCALE option (doesn't work!) 2015-11-28 13:13:44 +05:30
Sameer Naik a6a2a78585 readme: add imagelayers.io badge 2015-11-28 11:45:54 +05:30
Sameer Naik 2668b06886 readme: fixes 2015-11-27 19:36:13 +05:30
Sameer Naik 27ffe14e79 readme: moved Command-line arguments section before Logs 2015-11-27 18:01:36 +05:30
Sameer Naik 6c7706c8f1 readme: moved logs section towards the end 2015-11-27 18:00:01 +05:30
Sameer Naik 710299161a readme: fixed typo 2015-11-27 16:49:13 +05:30
Sameer Naik 22dba65610 add support for creating backups using pg_basebackup 2015-11-27 16:48:24 +05:30
Sameer Naik 73be444cea added missing ;; to case 2015-11-27 16:24:07 +05:30
Sameer Naik c7bae0d677 Merge branch 'complete-rewrite-and-reorg' 2015-11-27 15:44:26 +05:30
Sameer Naik c5522c9fda complete rewrite of the README 2015-11-27 15:39:10 +05:30
Sameer Naik ce2caf3937 DB_LOCALE config parameter renamed to PG_LOCALE 2015-11-27 15:02:50 +05:30
Sameer Naik 5e09110558 configure logging options on first run 2015-11-27 11:04:52 +05:30
Sameer Naik afe467bec7 added sample docker-compose.yml 2015-11-27 10:07:56 +05:30
Sameer Naik 7f1e051f1a remove extra whitespace 2015-11-26 22:29:20 +05:30
Sameer Naik 978c70a78a moved default script variables to env-defaults 2015-11-26 21:06:13 +05:30
Sameer Naik faaa87cc64 separated out entrypoint.sh functions to a functions bash module 2015-11-26 21:04:17 +05:30
Sameer Naik 6418c9e044 added PG_SSL parameter to enable/disable SSL support
`PG_SSL` is automatically set to `on` if `server.crt` and `server.key`
can be found at `/etc/postgresql/certs`

Closes #32
2015-11-26 21:03:51 +05:30
Sameer Naik 5f6024062f defined /etc/postgresql/certs as the mountpoint to install SSL key and certificate 2015-11-26 21:03:51 +05:30
Sameer Naik 7eeda81f1e set default value of REPLICATION_SSLMODE to prefer 2015-11-26 21:03:51 +05:30
Sameer Naik 761ec9645c PSQL_SSLMODE config parameter renamed to REPLICATION_SSLMODE 2015-11-26 21:03:51 +05:30
Sameer Naik b6f0cba6a7 PSQL_MODE config parameter renamed to REPLICATION_MODE 2015-11-26 21:03:51 +05:30
Sameer Naik de5295ffa7 PSQL_TRUST_LOCALNET config parameter renamed to PG_TRUST_LOCALNET 2015-11-26 21:03:51 +05:30
Sameer Naik c8e9dec549 complete rewrite of existing feature set
Closes #40
2015-11-26 21:03:49 +05:30
Sameer Naik a68b58aefe fix: set ssl config to off or on 2015-11-23 22:25:23 +05:30
Sameer Naik f3b18c1f1b avoid duplicate entries in configuration files. Refer #40 2015-11-23 20:46:11 +05:30
Sameer Naik b4a5810e13 readme: docker build one liner 2015-11-19 22:32:41 +05:30
Sameer Naik ca479d90cf release 9.4-8 2015-11-18 19:48:25 +05:30
Sameer Naik 8aa5c9b64f dockerfile: upgrade to sameersbn/ubuntu:14.04.20151117 2015-11-18 19:47:51 +05:30
Sameer Naik 728f606b4d Merge branch 'fix-replication'
Fixes #40
2015-11-15 13:04:10 +05:30
Sameer Naik b5dd975ad1 removed redundant chown of PG_CONFDIR 2015-11-15 13:02:50 +05:30
Sameer Naik 693995dd2b set PG_CONFDIR to ${PG_HOME}/${PG_VERSION}/main
Database initialization and migration tasks need to be done before
performing any configuration bits
2015-11-15 13:02:10 +05:30
Sameer Naik 7601996544 hub.docker.com now builds images from git tags. 2015-11-07 12:45:15 +05:30
Sameer Naik 4d92cfc63e release 9.4-7 2015-10-23 12:02:37 +05:30
Sameer Naik 6d98301424 dockerfile: upgrade to quay.io/sameersbn/ubuntu:14.04.20151023 2015-10-23 12:02:15 +05:30
Sameer Naik 4fa09528b6 Merge branch 'sdusart-master' 2015-10-17 15:29:57 +05:30
Sameer Naik a443dfb2d9 Merge branch 'master' of https://github.com/sdusart/docker-postgresql into sdusart-master 2015-10-17 15:29:17 +05:30
Sameer Naik b75f1ea632 release 9.4-6 2015-10-13 14:35:46 +05:30
Sameer Naik a934d8131c dockerfile: upgrade to quay.io/sameersbn/ubuntu:14.04.20151013 2015-10-13 14:35:15 +05:30
Sameer Naik 8f331ff0b3 readme: added quay.io badge 2015-10-12 12:13:23 +05:30
Sameer Naik d933707cad Makefile: tag builds with quay.io/sameersbn/ prefix 2015-10-11 17:14:40 +05:30
Sameer Naik f5f7c094a1 hello quay.io, bye-bye hub.docker.com 2015-10-11 16:01:06 +05:30
Sameer Naik ba8244feea release 9.4-5 2015-10-11 13:28:43 +05:30
Sameer Naik fae08e9091 dockerfile: upgrade to quay.io/sameersbn/ubuntu:14.04.20151011 2015-10-11 13:28:11 +05:30
Sameer Naik eedfc6a1c9 set DEBIAN_FRONTEND=noninteractive env setting apt-get install lines 2015-10-10 23:05:12 +05:30
Sylvain Dusart 57f7f6597c Add an option to set the locale used for database creation
Using the DB_LOCALE environment variable (set by default to C), it is now
possible to set the --locale argument that is given to the initdb command.
This enables customization of LC_COLLATE and LC_TYPE for the databases.
2015-10-03 23:49:28 +02:00
Sylvain Dusart fbc06c1604 Protect usernames and database names in "CREATE ROLE", "CREATE DATABASE" and "GRANT ALL" requests
This enables to use "-" in for usernames or database names (eg myApp-client1).
2015-10-03 21:09:39 +02:00
Sameer Naik 47f6fd61a7 release 9.4-4 2015-08-30 21:54:26 +05:30
Sameer Naik b3d5862cd1 dockerfile: upgrade to `sameersbn/ubuntu:14.04.20150825 2015-08-25 00:13:36 +05:30
Sameer Naik 7da82b6646 dockerfile: upgrade to `sameersbn/ubuntu:14.04.20150816 2015-08-16 19:59:14 +05:30
Sameer Naik 9ca966eb1f entrypoint.sh: chown recursively 2015-08-16 12:47:44 +05:30
Sameer Naik da0fb3dc36 entrypoint.sh: moved user mapping code to a function 2015-08-16 12:28:38 +05:30
Sameer Naik 306f915aaf entrypoint.sh: create log dir 2015-08-16 12:25:39 +05:30
Sameer Naik fd3794fa03 entrypoint.sh: moved data and run directiory creation into functions 2015-08-16 12:25:32 +05:30
Sameer Naik 3c5e076101 Dockerfile: added PG_RUNDIR variable 2015-08-16 12:12:30 +05:30
Sameer Naik 17c826882a renamed start script to entrypoint.sh 2015-08-16 11:38:25 +05:30
Sameer Naik c37ff75c41 release 9.4-3 2015-08-07 10:21:23 +05:30
Sameer Naik 2c1b7a1519 dockerfile: upgrade to `sameersbn/ubuntu:14.04.20150805 2015-08-05 13:25:30 +05:30
Sameer Naik 7bb94d25f9 Merge pull request #36 from timclassic/master
start: maybe change DSM config in postgresql.conf
2015-07-19 22:19:09 +05:30
Tim Stewart 28316a48f4 start: maybe change DSM config in postgresql.conf 2015-07-19 04:40:32 -04:00
Sameer Naik 58e1b2da94 release 9.4-2 2015-07-15 22:59:54 +05:30
Sameer Naik 2a86901c5f readme: updated contributing section 2015-07-13 14:53:42 +05:30
Sameer Naik 24a109da76 scripts: make use of [[ in conditional statements 2015-07-12 23:51:56 +05:30
Sameer Naik 691ca31510 dockerfile: use the PG_HOME macro where ever possible 2015-07-12 23:22:35 +05:30
Sameer Naik dfe862ad7e makefile: added release target 2015-07-12 23:21:22 +05:30
Sameer Naik dea4219815 correct the version in VERSION file 2015-07-12 23:21:22 +05:30
Sameer Naik ededd9a1fc dockerfile: replaced ADD with COPY instruction 2015-07-12 23:21:22 +05:30
Sameer Naik 7348f88758 dockerfile: explicitly specify protocol in EXPOSE instructions 2015-07-12 23:21:22 +05:30
Sameer Naik 2b6d6604a9 dockerfile: combine VOLUME instructions 2015-07-12 23:21:22 +05:30
Sameer Naik 8627633263 dockerfile: removed date tag from main apt-get command 2015-07-12 23:21:22 +05:30
Sameer Naik c065419269 dockerfile: moved main script variables to Dockerfile 2015-07-12 23:21:21 +05:30
Sameer Naik 8d4025257f start: combine sudo arguments 2015-07-12 23:20:50 +05:30
Sameer Naik 87857b903f dockerfile: added PG_USER variable 2015-07-12 23:20:49 +05:30
Sameer Naik a22c6032ec entrypoint.sh: rewrite user mapping code 2015-07-12 23:19:11 +05:30
Sameer Naik 6237bf1164 dockerfile: upgrade to `sameersbn/ubuntu:14.04.20150712 2015-07-12 00:10:58 +05:30
Sameer Naik b0102f69e7 start: launch postgresql server using start-stop-daemon 2015-07-11 21:49:20 +05:30
Sameer Naik f0c4e38261 changelog: updated 2015-07-11 21:47:45 +05:30
Sameer Naik 3fe050caf2 readme: moved Shell Access as the last section 2015-07-11 20:36:22 +05:30
Sameer Naik 43b64e09e5 readme: moved user mapping sectio before Shell Access 2015-07-11 20:35:05 +05:30
Sameer Naik 02927cdae7 readme: renamed Data store section to Persistence, and moved it to the top 2015-07-11 20:34:04 +05:30
Sameer Naik 77bc912ed1 readme: removed configuration section 2015-07-11 20:32:55 +05:30
Sameer Naik 8de5ac9829 readme: create database and user in replication example 2015-07-11 20:31:40 +05:30
Sameer Naik a9e44ea16d readme: use only docker containers to demo replication 2015-07-11 19:56:41 +05:30
Sameer Naik 5105cd9b70 readme: formatting 2015-07-11 19:49:46 +05:30
Sameer Naik 3d90afa4c6 start: removed PSQL_ARCHIVEMODE related stuff 2015-07-11 19:43:14 +05:30
Sameer Naik cd6fef8397 Merge branch 'Downchuck-master' 2015-07-11 19:40:39 +05:30
Sameer Naik f229f9d3b1 Merge branch 'master' of https://github.com/Downchuck/docker-postgresql into Downchuck-master 2015-07-11 19:40:21 +05:30
Sameer Naik a4802bce49 Merge pull request #33 from fredrikmollerstrand/speling-fixes
fix a few typos
2015-07-02 22:01:29 +05:30
Fredrik Möllerstrand 09a6cad414 fix a few typos 2015-07-02 17:04:29 +01:00
Charles Pritchard 9dd5b55b3a Create PSQL_MODE master, slave and snapshot for pg_basebackup and streaming replication 2015-06-26 14:44:11 -04:00
Sameer Naik b56a5fd91e release 9.4-1 2015-06-17 12:23:07 +05:30
Sameer Naik 209a5f095a dockerfile: upgrade to `sameersbn/ubuntu:14.04.20150613 2015-06-13 13:12:18 +05:30
Sameer Naik 353b4b1bc7 start: use gosu to launch the daemon 2015-06-04 10:50:19 +05:30
Sameer Naik ed45b2b3f1 dockerfile: upgrade to sameersbn/ubuntu:14.04.20150604 2015-06-04 10:50:15 +05:30
Sameer Naik 2c282c41af dockerfile: upgrade to sameersbn/ubuntu:14.04.20150603 2015-06-03 12:03:59 +05:30
Sameer Naik 69f62d13fb changelog: updated 2015-05-30 13:41:08 +05:30
Sameer Naik 328e31bdcd Merge branch 'TimNN-usermap' 2015-05-30 13:39:37 +05:30
Tim Neumann df2a0478d0 add support for USERMAP_* env variables 2015-05-26 22:21:26 +02:00
Sameer Naik 18c17a1a52 ci: removed --rm flag from postgresql conninfo test 2015-05-05 11:48:05 +05:30
Sameer Naik ca237ff80c ci: use the postgresql image to test the postgresql server 2015-05-05 11:45:23 +05:30
Sameer Naik a0579ee8a1 ci: avoid using docker bridge ip in tests 2015-05-05 10:27:21 +05:30
Sameer Naik 83733cc469 ci: changed published port number in tests 2015-05-05 10:16:55 +05:30
Sameer Naik 71d9e80152 readme: added build status badge 2015-05-05 10:09:50 +05:30
Sameer Naik c777d2abe6 updated .dockerignore 2015-05-05 10:09:35 +05:30
Sameer Naik 6608fd24bc ci: added circle.yml 2015-05-05 10:09:10 +05:30
Sameer Naik ebb171489a baseimage: upgrade to sameersbn/ubuntu:14.04.20150504 2015-05-04 12:59:59 +05:30
Sameer Naik 788be37f87 readme: updated to remove information regarding the pwfile 2015-04-14 16:36:10 +05:30
Sameer Naik a0e0231358 dockerfile: removed unused pwgen package 2015-04-14 16:30:55 +05:30
Sameer Naik eb5e3600d1 start: removed pwfile logic 2015-04-14 16:30:29 +05:30
Sameer Naik 678031d48d baseimage: upgrade to sameersbn/ubuntu:14.04.20150323 2015-03-23 11:37:51 +05:30
Sameer Naik a79e655a39 Merge pull request #18 from Huttopia/master
Fix installation unaccent extension - specify databases
2015-03-06 15:07:57 +05:30
Cédric Vanet defe9ff649 Fix installing unaccent extension - specify databases 2015-03-06 10:34:06 +01:00
Sameer Naik f88ada5af0 Merge branch 'Huttopia-master' 2015-02-27 18:08:48 +05:30
Cédric Vanet 9cca232ba0 Add unaccent extension 2015-02-27 11:33:46 +01:00
Sameer Naik 638dd689bd upgrade to sameersbn/ubuntu:14.04.20150220 2015-02-20 13:28:53 +05:30
Sameer Naik 1184d9e566 start: fix PSQL_TRUST_LOCALNET enabled check 2015-02-15 08:43:42 +05:30
Sameer Naik fec631fe5a Merge pull request #15 from lgfausak/master
swapped two pg_hba.conf updates.
2015-02-10 21:34:06 +05:30
Greg Fausak a1486868fa swapped two pg_hba.conf updates. 2015-02-10 13:38:49 +00:00
Sameer Naik c5a9e8cdb2 start: clean up 2015-02-08 12:06:15 +05:30
Sameer Naik 5d4cff076a start: use true/false for PSQL_TRUST_LOCALNET configuration 2015-02-08 12:03:48 +05:30
Sameer Naik 8ed8d2e0f5 Merge branch 'tacodata-master' 2015-02-08 12:00:39 +05:30
Greg Fausak d01ae5e1d7 oops, got the environment var wrong 2015-02-07 19:27:20 +00:00
Greg Fausak 1873e0d389 make the trust samenet behavior triggered by the PSQL_TRUST_LOCALNET environment variable 2015-02-07 15:30:44 +00:00
Greg Fausak eaa8ee9bce added trust on samenet in pg_hba 2015-02-06 17:29:27 +00:00
Sameer Naik 25350fb87e start: do not silence postgresql command errors 2015-02-04 16:03:18 +05:30
Sameer Naik cf166ff153 start: silence find errors 2015-02-04 16:03:00 +05:30
Sameer Naik 3230aafc6c release 9.4 2015-02-04 15:05:41 +05:30
Sameer Naik afdf196abc postgresql: upgrade to 9.4
Close #8
2015-02-04 14:54:14 +05:30
Sameer Naik 8a30ea03fc release 9.1-2 2015-02-04 14:50:40 +05:30
Sameer Naik f94ab9511e Merge branch 'automatic-upgrades' 2015-02-04 14:41:27 +05:30
Sameer Naik df890a902f start: automatically migrate postgresql data on upgrades 2015-02-04 14:41:13 +05:30
Sameer Naik 2af478b7cd start: create pwfile only if it does not already exist 2015-02-04 13:58:56 +05:30
Sameer Naik f75e33f072 start: added PG_HOME macro 2015-02-03 21:34:22 +05:30
Sameer Naik 65ad3beacf dockerfile: define PG_VERSION as an ENV variable 2015-02-03 10:40:20 +05:30
Sameer Naik a93afd52f8 changelog: updated 2015-02-02 23:41:25 +05:30
Sameer Naik 66a27426e6 dockerfile: base image on sameersbn/ubuntu:14.04.20150120 2015-02-02 23:39:14 +05:30
Sameer Naik 5a529a52ab dockerfile: use postgresql apt repository 2015-02-02 23:38:30 +05:30
Sameer Naik 2518d62378 upgrade to sameersbn/ubuntu:12.04.20150120 2015-01-20 15:12:19 +05:30
Sameer Naik 1a7390c746 start: allow creation of multiple databases at launch
Refer #11
2015-01-05 11:18:29 +05:30
Sameer Naik 90f35e89b9 dockerfile: upgrade to sameersbn/ubuntu:14.04.20141218 2014-12-18 11:38:07 +05:30
Sameer Naik e0478a049b add license file 2014-12-09 22:46:29 +05:30
Sameer Naik feecacfdf2 readme: document use of docker exec for shell access 2014-11-25 10:47:08 +05:30
Sameer Naik df2638881b readme: use coinbase link 2014-11-25 10:47:00 +05:30
Sameer Naik cf2d42797b Merge pull request #9 from flecno/patch-1
Update README.md
2014-11-17 09:14:16 +05:30
Timo Zingel 68977a5d19 Update README.md 2014-11-16 19:31:28 +01:00
Sameer Naik 8b52c4e35a readme: specify image version in administrative login command 2014-10-27 20:14:48 +05:30
Sameer Naik 22953b3498 dockerfile: upgrade to sameersbn/ubuntu:14.04.20141026 base image 2014-10-26 20:25:00 +05:30
Sameer Naik b2ab257dd6 readme: added "Contributing" section 2014-10-26 20:24:55 +05:30
Sameer Naik d07407dd75 readme: use tagged images in docker commands 2014-10-06 17:33:55 +05:30
Sameer Naik ef07c65029 release 9.1-1 2014-10-06 17:30:49 +05:30
Sameer Naik b3ca9b453b upgrade to sameersbn/ubuntu:20141001, fixes shellshock 2014-10-01 09:40:37 +05:30
Sameer Naik 7bec626f6a dockerfile: install pwgen package (has been removed from the base image) 2014-09-30 19:58:49 +05:30
Sameer Naik cc065698f1 readme: fix typo 2014-09-29 14:00:59 +05:30
Sameer Naik 6a4fe7ca5b readme: added instructions to login as postgres user using the --volumes-from docker option 2014-09-29 14:00:03 +05:30
Sameer Naik 370e1aea63 start: support creation of user and database at launch
Refer #5
2014-09-27 14:10:32 +05:30
Sameer Naik 916a36f163 added Makefile 2014-09-22 14:19:19 +05:30
Sameer Naik c590589aab create the /var/lib/postgresql directory at start 2014-09-20 09:56:12 +05:30
Sameer Naik 534854552d create the /run/postgresql directory at start 2014-09-20 09:55:54 +05:30
Sameer Naik 737747191f use the /run/postgresql path while fixing permissions 2014-09-20 09:54:16 +05:30
Sameer Naik 66b92b361c Merge branch 'shcarrico-modify-run-volume' 2014-09-20 09:50:42 +05:30
Stan Carrico 92e7c5c8c2 run volume does not mount, /var/run is a symlink to /run 2014-09-19 19:43:04 -07:00
Sameer Naik c3b94e501d added changelog.md 2014-09-04 14:28:23 +05:30
Sameer Naik d33c7cb512 dockerfile: clean up 2014-09-04 14:24:04 +05:30
Sameer Naik abcbb9b17d dockerfile readability updates 2014-09-04 14:23:45 +05:30
Sameer Naik 81786d6f16 dockerfile: added volume mount instruction for /var/run/postgresql 2014-09-04 14:23:10 +05:30
Sameer Naik e0ce5c7005 make sure /var/run/postgresql has the right permissions
Users should be able mount at volume at /var/run/postgresql so as to expose the postgresql unix socket.
2014-09-04 14:21:47 +05:30
Sameer Naik a37704e05e added note about selinux and mountpoints 2014-09-02 11:19:50 +05:30
Sameer Naik 5023375538 beautify readme 2014-09-02 11:18:06 +05:30
Sameer Naik 4083c2af1c added .dockerignore file 2014-09-02 11:10:12 +05:30
Sameer Naik cc675068ef readme: added section on reporting issues 2014-09-02 11:08:51 +05:30
Sameer Naik 1c866afa02 readme: added section on acquiring shell access to the container 2014-09-02 11:07:35 +05:30
13 changed files with 872 additions and 118 deletions
+7
View File
@@ -0,0 +1,7 @@
.git
circle.yml
LICENSE
VERSION
README.md
Changelog.md
Makefile
+42
View File
@@ -0,0 +1,42 @@
# Changelog
**9.4-11**
- added `PG_PASSWORD` variable to specify password for `postgres` user
**9.4-9**
- complete rewrite
- `PSQL_TRUST_LOCALNET` config parameter renamed to `PG_TRUST_LOCALNET`
- `PSQL_MODE` config parameter renamed to `REPLICATION_MODE`
- `PSQL_SSLMODE` config parameter renamed to `REPLICATION_SSLMODE`
- defined `/etc/postgresql/certs` as the mountpoint to install SSL key and certificate
- added `PG_SSL` parameter to enable/disable SSL support
- `DB_LOCALE` config parameter renamed to `PG_LOCALE`
- complete rewrite of the README
- add support for creating backups using `pg_basebackup`
- removed `PG_LOCALE` option (doesn't work!)
- added `DEBUG` option to enable bash debugging
**9.4-2**
- added replication options
**9.4-1**
- start: removed `pwfile` logic
- init: added `USERMAP_*` configuration options
- base image update to fix SSL vulnerability
**9.4**
- postgresql: upgrade to 9.4
**9.1-2**
- use the official postgresql apt repo
- feature: automatic data migration on upgrade
**9.1-1**
- upgrade to sameersbn/ubuntu:20141001, fixes shellshock
- support creation of users and databases at launch (`docker run`)
- mount volume at `/var/run/postgresql` allowing the postgresql unix socket to be exposed
**9.1**
- optimized image size by removing `/var/lib/apt/lists/*`.
- update to the sameersbn/ubuntu:12.04.20140818 baseimage
- removed use of supervisord
+28 -10
View File
@@ -1,14 +1,32 @@
FROM sameersbn/ubuntu:12.04.20140818 FROM sameersbn/ubuntu:14.04.20151213
MAINTAINER sameer@damagehead.com MAINTAINER sameer@damagehead.com
RUN apt-get update && \ ENV PG_APP_HOME="/etc/docker-postgresql"\
apt-get install -y --no-install-recommends postgresql postgresql-client && \ PG_VERSION=9.4 \
rm -rf /var/lib/postgresql && \ PG_USER=postgres \
rm -rf /var/lib/apt/lists/* # 20140818 PG_HOME=/var/lib/postgresql \
PG_RUNDIR=/run/postgresql \
PG_LOGDIR=/var/log/postgresql \
PG_CERTDIR=/etc/postgresql/certs
ADD start /start ENV PG_BINDIR=/usr/lib/postgresql/${PG_VERSION}/bin \
RUN chmod 755 /start PG_DATADIR=${PG_HOME}/${PG_VERSION}/main
EXPOSE 5432 RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
VOLUME ["/var/lib/postgresql"] && echo 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' > /etc/apt/sources.list.d/pgdg.list \
CMD ["/start"] && apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-${PG_VERSION} postgresql-client-${PG_VERSION} postgresql-contrib-${PG_VERSION} \
&& ln -sf ${PG_DATADIR}/postgresql.conf /etc/postgresql/${PG_VERSION}/main/postgresql.conf \
&& ln -sf ${PG_DATADIR}/pg_hba.conf /etc/postgresql/${PG_VERSION}/main/pg_hba.conf \
&& ln -sf ${PG_DATADIR}/pg_ident.conf /etc/postgresql/${PG_VERSION}/main/pg_ident.conf \
&& rm -rf ${PG_HOME} \
&& rm -rf /var/lib/apt/lists/*
COPY runtime/ ${PG_APP_HOME}/
COPY entrypoint.sh /sbin/entrypoint.sh
RUN chmod 755 /sbin/entrypoint.sh
EXPOSE 5432/tcp
VOLUME ["${PG_HOME}", "${PG_RUNDIR}"]
WORKDIR ${PG_HOME}
ENTRYPOINT ["/sbin/entrypoint.sh"]
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Sameer Naik
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+7
View File
@@ -0,0 +1,7 @@
all: build
build:
@docker build --tag=sameersbn/postgresql .
release: build
@docker build --tag=sameersbn/postgresql:$(shell cat VERSION) .
+327 -58
View File
@@ -1,113 +1,382 @@
# Table of Contents [![Circle CI](https://circleci.com/gh/sameersbn/docker-postgresql.svg?style=shield)](https://circleci.com/gh/sameersbn/docker-postgresql) [![Docker Repository on Quay.io](https://quay.io/repository/sameersbn/postgresql/status "Docker Repository on Quay.io")](https://quay.io/repository/sameersbn/postgresql) [![](https://badge.imagelayers.io/sameersbn/postgresql.svg)](https://imagelayers.io/?images=sameersbn/postgresql:latest 'Get your own badge on imagelayers.io')
# sameersbn/postgresql:9.4-11
- [Introduction](#introduction) - [Introduction](#introduction)
- [Installation](#installation) - [Contributing](#contributing)
- [Quick Start](#quick-start) - [Issues](#issues)
- [Configuration](#configuration) - [Getting started](#getting-started)
- [Data Store](#data-store) - [Installation](#installation)
- [Securing the server](#securing-the-server) - [Quickstart](#quickstart)
- [Upgrading](#upgrading) - [Persistence](#persistence)
- [Issues](#issues) - [Trusting local connections](#trusting-local-connections)
- [Setting `postgres` user password](#setting-postgres-user-password)
- [Creating database user](#creating-database-user)
- [Creating databases](#creating-databases)
- [Enabling unaccent extension](#enabling-unaccent-extension)
- [Granting user access to a database](#granting-user-access-to-a-database)
- [Creating replication user](#creating-replication-user)
- [Setting up a replication cluster](#setting-up-a-replication-cluster)
- [Creating a snapshot](#creating-a-snapshot)
- [Creating a backup](#creating-a-backup)
- [Command-line arguments](#command-line-arguments)
- [Logs](#logs)
- [UID/GID mapping](#uid-gid-mapping)
- [Maintenance](#maintenance)
- [Upgrading](#upgrading)
- [Shell Access](#shell-access)
# Introduction # Introduction
Dockerfile to build a PostgreSQL container image which can be linked to other containers.
# Installation `Dockerfile` to create a [Docker](https://www.docker.com/) container image for [PostgreSQL](http://postgresql.org/).
Pull the latest version of the image from the docker index. This is the recommended method of installation as it is easier to update image in the future. These builds are performed by the **Docker Trusted Build** service. PostgreSQL is an object-relational database management system (ORDBMS) with an emphasis on extensibility and standards-compliance [[source](https://en.wikipedia.org/wiki/PostgreSQL)].
## Contributing
If you find this image useful here's how you can help:
- Send a pull request with your awesome features and bug fixes
- Help users resolve their [issues](../../issues?q=is%3Aopen+is%3Aissue).
- Support the development of this image with a [donation](http://www.damagehead.com/donate/)
## Issues
Before reporting your issue please try updating Docker to the latest version and check if it resolves the issue. Refer to the Docker [installation guide](https://docs.docker.com/installation) for instructions.
SELinux users should try disabling SELinux using the command `setenforce 0` to see if it resolves the issue.
If the above recommendations do not help then [report your issue](../../issues/new) along with the following information:
- Output of the `docker version` and `docker info` commands
- The `docker run` command or `docker-compose.yml` used to start the image. Mask out the sensitive bits.
- Please state if you are using [Boot2Docker](http://www.boot2docker.io), [VirtualBox](https://www.virtualbox.org), etc.
# Getting started
## Installation
Automated builds of the image are available on [Dockerhub](https://hub.docker.com/r/sameersbn/postgresql) and is the recommended method of installation.
> **Note**: Builds are also available on [Quay.io](https://quay.io/repository/sameersbn/postgresql)
```bash ```bash
docker pull sameersbn/postgresql:latest docker pull sameersbn/postgresql:9.4-11
``` ```
Alternately you can build the image yourself. Alternatively you can build the image yourself.
```bash ```bash
git clone https://github.com/sameersbn/docker-postgresql.git docker build -t sameersbn/postgresql github.com/sameersbn/docker-postgresql
cd docker-postgresql
docker build -t="$USER/postgresql" .
``` ```
# Quick Start ## Quickstart
Run the postgresql image
Start PostgreSQL using:
```bash ```bash
docker run --name postgresql -d sameersbn/postgresql:latest docker run --name postgresql -itd --restart always \
--publish 5432:5432 \
--volume /srv/docker/postgresql:/var/lib/postgresql \
sameersbn/postgresql:9.4-11
``` ```
By default remote logins are permitted to the postgresql server and a random password is assigned for the postgres user. The password set for the postgres user can be retrieved from the container logs. Login to the PostgreSQL server using:
```bash ```bash
docker logs postgresql docker exec -it postgresql sudo -u postgres psql
``` ```
In the output you will notice the following lines with the password: *Alternatively, you can use the sample [docker-compose.yml](docker-compose.yml) file to start the container using [Docker Compose](https://docs.docker.com/compose/)*
```bash
|------------------------------------------------------------------|
| PostgreSQL User: postgres, Password: xxxxxxxxxxxxxx |
| |
| To remove the PostgreSQL login credentials from the logs, please |
| make a note of password and then delete the file pwfile |
| from the data store. |
|------------------------------------------------------------------|
```
To test if the postgresql server is working properly, try connecting to the server. ## Persistence
For PostgreSQL to preserve its state across container shutdown and startup you should mount a volume at `/var/lib/postgresql`.
> *The [Quickstart](#quickstart) command already mounts a volume for persistence.*
SELinux users should update the security context of the host mountpoint so that it plays nicely with Docker:
```bash ```bash
psql -U postgres -h $(docker inspect --format {{.NetworkSettings.IPAddress}} postgresql) mkdir -p /srv/docker/postgresql
chcon -Rt svirt_sandbox_file_t /srv/docker/postgresql
``` ```
# Configuration ## Trusting local connections
## Data Store By default connections to the PostgreSQL server need to authenticated using a password. If desired you can trust connections from the local network using the `PG_TRUST_LOCALNET` variable.
For data persistence a volume should be mounted at /var/lib/postgresql.
```bash ```bash
mkdir /opt/postgresql/data docker run --name postgresql -itd --restart always \
docker run --name postgresql -d \ --env 'PG_TRUST_LOCALNET=true' \
-v /opt/postgresql/data:/var/lib/postgresql sameersbn/postgresql:latest sameersbn/postgresql:9.4-11
``` ```
This will make sure that the data stored in the database is not lost when the image is stopped and started again. > **Note**
>
> The local network here is network to which the container is attached. This has different meanings depending on the `--net` parameter specified while starting the container. In the default configuration, this parameter would trust connections from other containers on the `docker0` bridge.
## Securing the server ## Setting `postgres` user password
By default a randomly generated password is assigned for the postgres user. The password is stored in a file named pwpass in the data store and is printed in the logs.
If you dont want this password to be displayed in the logs, then please note down the password listed in /opt/postgresql/data/pwpass and then delete the file. By default the `postgres` user is not assigned a password and as a result you can only login to the PostgreSQL server locally. If you wish to login remotely to the PostgreSQL server as the `postgres` user, you will need to assign a password for the user using the `PG_PASSWORD` variable.
```bash ```bash
cat /opt/postgresql/data/pwfile docker run --name postgresql -itd --restart always \
rm /opt/postgresql/data/pwfile --env 'PG_PASSWORD=passw0rd' \
sameersbn/postgresql:9.4-11
``` ```
Alternately, you can change the password of the postgres user
> **Note**
>
> - When [persistence](#persistence) is in use, `PG_PASSWORD` is effective on the first run.
> - This feature is only available in the `latest` and versions > `9.4-10`
## Creating database user
A new PostgreSQL database user can be created by specifying the `DB_USER` and `DB_PASS` variables while starting the container.
```bash ```bash
psql -U postgres -h $(docker inspect --format {{.NetworkSettings.IPAddress}} postgresql) docker run --name postgresql -itd --restart always \
\password postgres --env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
sameersbn/postgresql:9.4-11
``` ```
# Upgrading > **Notes**
>
> - The created user can login remotely
> - The container will error out if a password is not specified for the user
> - No changes will be made if the user already exists
> - Only a single user can be created at each launch
To upgrade to newer releases, simply follow this 3 step upgrade procedure. ## Creating databases
- **Step 1**: Stop the currently running image A new PostgreSQL database can be created by specifying the `DB_NAME` variable while starting the container.
```bash ```bash
docker stop postgresql docker run --name postgresql -itd --restart always \
--env 'DB_NAME=dbname' \
sameersbn/postgresql:9.4-11
``` ```
- **Step 2**: Update the docker image. Additionally, more than one database can be created by specifying a comma separated list of database names in `DB_NAME`. For example, the following command creates two new databases named `dbname1` and `dbname2`.
*This feature is only available in releases greater than `9.1-1`*
```bash ```bash
docker pull sameersbn/postgresql:latest docker run --name postgresql -itd --restart always \
--env 'DB_NAME=dbname1,dbname2' \
sameersbn/postgresql:9.4-11
``` ```
- **Step 3**: Start the image # Enabling unaccent extension
Unaccent is a text search dictionary that removes accents (diacritic signs) from lexemes. It's a filtering dictionary, which means its output is always passed to the next dictionary (if any), unlike the normal behavior of dictionaries. This allows accent-insensitive processing for full text search [[source](http://www.postgresql.org/docs/9.4/static/unaccent.html)].
You can enable the unaccent extension on database(s) by specifying `DB_UNACCENT=true`. For example, the following command enables the unaccent extension for the `dbname` database.
```bash ```bash
docker run --name postgresql -d [OPTIONS] sameersbn/postgresql:latest docker run --name postgresql -itd \
--env 'DB_NAME=dbname' --env 'DB_UNACCENT=true' \
sameersbn/postgresql:9.4-11
``` ```
# Issues *By default the unaccent extension is disabled*
Please report issues [here](https://github.com/sameersbn/docker-postgresql/issues)
## Granting user access to a database
If the `DB_USER` and `DB_PASS` variables are specified along with the `DB_NAME` variable, then the user specified in `DB_USER` will be granted access to all the databases listed in `DB_NAME`. Note that if the user and/or databases do not exist, they will be created.
```bash
docker run --name postgresql -itd --restart always \
--env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' \
--env 'DB_NAME=dbname1,dbname2' \
sameersbn/postgresql:9.4-11
```
In the above example `dbuser` with be granted access to both the `dbname1` and `dbname2` databases.
## Creating replication user
Similar to the creation of a database user, a new PostgreSQL replication user can be created by specifying the `REPLICATION_USER` and `REPLICATION_PASS` variables while starting the container.
```bash
docker run --name postgresql -itd --restart always \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-11
```
> **Notes**
>
> - The created user can login remotely
> - The container will error out if a password is not specified for the user
> - No changes will be made if the user already exists
> - Only a single user can be created at each launch
*It is a good idea to create a replication user even if you are not going to use it as it will allow you to setup slave nodes and/or generate snapshots and backups when the need arises.*
## Setting up a replication cluster
When the container is started, it is by default configured to act as a master node in a replication cluster. This means that you can scale your PostgreSQL database backend when the need arises without incurring any downtime. However do note that a replication user must exist on the master node for this to work.
Begin by creating the master node of our cluster:
```bash
docker run --name postgresql-master -itd --restart always \
--env 'DB_USER=dbuser' --env 'DB_PASS=dbuserpass' --env 'DB_NAME=dbname' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-11
```
Notice that no additional arguments are specified while starting the master node of the cluster.
To create a replication slave the `REPLICATION_MODE` variable should be set to `slave` and additionally the `REPLICATION_HOST`, `REPLICATION_PORT`, `REPLICATION_SSLMODE`, `REPLICATION_USER` and `REPLICATION_PASS` variables should be specified.
Create a slave node:
```bash
docker run --name postgresql-slave01 -itd --restart always \
--link postgresql-master:master \
--env 'REPLICATION_MODE=slave' --env 'REPLICATION_SSLMODE=prefer' \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-11
```
*In the above command, we used docker links so that we can address the master node using the `master` alias in `REPLICATION_HOST`.*
> **Note**
>
> - The default value of `REPLICATION_PORT` is `5432`
> - The default value of `REPLICATION_SSLMODE` is `prefer`
> - The value of `REPLICATION_USER` and `REPLICATION_PASS` should be the same as the ones specified on the master node.
> - With [persistence](#persistence) in use, if the container is stopped and started, for the container continue to function as a slave you need to ensure that `REPLICATION_MODE=slave` is defined in the containers environment. In the absense of which the slave configuration will be turned off and the node will allow writing to it while having the last synced data from the master.
And just like that with minimal effort you have a PostgreSQL replication cluster setup. You can create additional slaves to scale the cluster horizontally.
Here are some important notes about a PostgreSQL replication cluster:
- Writes can only occur on the master
- Slaves are read-only
- For best performance, limit the reads to the slave nodes
## Creating a snapshot
Similar to a creating replication slave node, you can create a snapshot of the master by specifying `REPLICATION_MODE=snapshot`.
Once the master node is created as specified in [Setting up a replication cluster](#setting-up-a-replication-cluster), you can create a snapshot using:
```bash
docker run --name postgresql-snapshot -itd --restart always \
--link postgresql-master:master \
--env 'REPLICATION_MODE=snapshot' --env 'REPLICATION_SSLMODE=prefer' \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
sameersbn/postgresql:9.4-11
```
The difference between a slave and a snapshot is that a slave is read-only and updated whenever the master data is updated (streaming replication), while a snapshot is read-write and is not updated after the initial snapshot of the data from the master.
This is useful for developers to quickly snapshot the current state of a live database and use it for development/debugging purposes without altering the database on the live instance.
## Creating a backup
Just as the case of setting up a slave node or generating a snapshot, you can also create a backup of the data on the master by specifying `REPLICATION_MODE=backup`.
> The backups are generated with [pg_basebackup](http://www.postgresql.org/docs/9.4/static/app-pgbasebackup.html) using the replication protocol.
Once the master node is created as specified in [Setting up a replication cluster](#setting-up-a-replication-cluster), you can create a point-in-time backup using:
```bash
docker run --name postgresql-backup -it --rm \
--link postgresql-master:master \
--env 'REPLICATION_MODE=backup' --env 'REPLICATION_SSLMODE=prefer' \
--env 'REPLICATION_HOST=master' --env 'REPLICATION_PORT=5432' \
--env 'REPLICATION_USER=repluser' --env 'REPLICATION_PASS=repluserpass' \
--volume /srv/docker/backups/postgresql.$(date +%Y%m%d%H$M%S):/var/lib/postgresql \
sameersbn/postgresql:9.4-11
```
Once the backup is generated, the container will exit and the backup of the master data will be available at `/srv/docker/backups/postgresql.XXXXXXXXXXXX/`. Restoring the backup involves starting a container with the data in `/srv/docker/backups/postgresql.XXXXXXXXXXXX`.
## Command-line arguments
You can customize the launch command of PostgreSQL server by specifying arguments for `postgres` on the `docker run` command. For example the following command enables connection logging:
```bash
docker run --name postgresql -itd --restart always \
sameersbn/postgresql:9.4-11 -c log_connections=on
```
Please refer to the documentation of [postgres](http://www.postgresql.org/docs/9.4/static/app-postgres.html) for the complete list of available options.
## Logs
By default the PostgreSQL server logs are sent to the standard output. Using the [Command-line arguments](#command-line-arguments) feature you can configure the PostgreSQL server to send the log output to a file using the `-c logging_collector=on` argument:
```bash
docker run --name postgresql -itd --restart always \
sameersbn/postgresql:9.4-11 -c logging_collector=on
```
To access the PostgreSQL logs you can use `docker exec`. For example:
```bash
docker exec -it postgresql tail -f /var/log/postgresql/postgresql-9.4-main.log
```
# UID/GID mapping
The files and processes created by the container are owned by the `postgres` user that is internal to the container. In the absense of user namespace in docker the UID and GID of the containers `postgres` user may have different meaning on the host.
For example, a user on the host with the same UID and/or GID as the `postgres` user of the container will be able to access the data in the persistent volumes mounted from the host as well as be able to KILL the `postgres` server process started by the container.
To circumvent this issue you can specify the UID and GID for the `postgres` user of the container using the `USERMAP_UID` and `USERMAP_GID` variables respectively.
For example, if you want to assign the `postgres` user of the container the UID and GID `999`:
```bash
docker run --name postgresql -itd --restart always \
--env 'USERMAP_UID=999' --env 'USERMAP_GID=999' \
sameersbn/postgresql:9.4-11
```
# Maintenance
## Upgrading
To upgrade to newer releases:
1. Download the updated Docker image:
```bash
docker pull sameersbn/postgresql:9.4-11
```
2. Stop the currently running image:
```bash
docker stop postgresql
```
3. Remove the stopped container
```bash
docker rm -v postgresql
```
4. Start the updated image
```bash
docker run --name postgresql -itd \
[OPTIONS] \
sameersbn/postgresql:9.4-11
```
## Shell Access
For debugging and maintenance purposes you may want access the containers shell. If you are using Docker version `1.3.0` or higher you can access a running containers shell by starting `bash` using `docker exec`:
```bash
docker exec -it postgresql bash
```
+1 -1
View File
@@ -1 +1 @@
9.1 9.4-11
+15
View File
@@ -0,0 +1,15 @@
machine:
services:
- docker
dependencies:
cache_directories:
- "~/docker-postgresql"
override:
- docker info
- if [[ -e ~/docker-postgresql/image.tar ]]; then docker load --input ~/docker-postgresql/image.tar; fi
- docker build -t sameersbn/postgresql .
- mkdir -p ~/docker-postgresql; docker save --output ~/docker-postgresql/image.tar sameersbn/postgresql
test:
override:
- docker run -d --name=postgresql sameersbn/postgresql; sleep 10
- docker run -it --volumes-from=postgresql sameersbn/postgresql sudo -u postgres -H psql -c "\conninfo"
+16
View File
@@ -0,0 +1,16 @@
PostgreSQL:
restart: always
image: sameersbn/postgresql:9.4-11
ports:
- "5432:5432"
environment:
- DEBUG=false
- DB_USER=
- DB_PASS=
- DB_NAME=
- REPLICATION_MODE=
- REPLICATION_USER=
- REPLICATION_PASS=
- REPLICATION_SSLMODE=
volumes:
- /srv/docker/postgresql:/var/lib/postgresql
Executable
+40
View File
@@ -0,0 +1,40 @@
#!/bin/bash
set -e
source ${PG_APP_HOME}/functions
[[ ${DEBUG} == true ]] && set -x
# allow arguments to be passed to postgres
if [[ ${1:0:1} = '-' ]]; then
EXTRA_ARGS="$@"
set --
elif [[ ${1} == postgres || ${1} == $(which postgres) ]]; then
EXTRA_ARGS="${@:2}"
set --
fi
# default behaviour is to launch postgres
if [[ -z ${1} ]]; then
map_uidgid
create_datadir
create_certdir
create_logdir
create_rundir
initialize_database
configure_recovery
configure_ssl
trust_localnet
create_user
create_database
create_replication_user
echo "Starting PostgreSQL ${PG_VERSION}..."
exec start-stop-daemon --start --chuid ${PG_USER}:${PG_USER} \
--exec ${PG_BINDIR}/postgres -- -D ${PG_DATADIR} ${EXTRA_ARGS}
else
exec "$@"
fi
+20
View File
@@ -0,0 +1,20 @@
#!/bin/bash
PG_SSL=${PG_SSL:-}
PG_TRUST_LOCALNET=${PG_TRUST_LOCALNET:-$PSQL_TRUST_LOCALNET} # backward compatibility
PG_TRUST_LOCALNET=${PG_TRUST_LOCALNET:-false}
REPLICATION_MODE=${REPLICATION_MODE:-$PSQL_MODE} # backward compatibility
REPLICATION_MODE=${REPLICATION_MODE:-}
REPLICATION_USER=${REPLICATION_USER:-}
REPLICATION_PASS=${REPLICATION_PASS:-}
REPLICATION_HOST=${REPLICATION_HOST:-}
REPLICATION_PORT=${REPLICATION_PORT:-5432}
REPLICATION_SSLMODE=${REPLICATION_SSLMODE:-prefer}
DB_NAME=${DB_NAME:-}
DB_USER=${DB_USER:-}
DB_PASS=${DB_PASS:-}
DB_UNACCENT=${DB_UNACCENT:-false}
+348
View File
@@ -0,0 +1,348 @@
#!/bin/bash
set -e
source ${PG_APP_HOME}/env-defaults
PG_CONF=${PG_DATADIR}/postgresql.conf
PG_HBA_CONF=${PG_DATADIR}/pg_hba.conf
PG_IDENT_CONF=${PG_DATADIR}/pg_ident.conf
PG_RECOVERY_CONF=${PG_DATADIR}/recovery.conf
## Execute command as PG_USER
exec_as_postgres() {
sudo -HEu ${PG_USER} "$@"
}
map_uidgid() {
USERMAP_ORIG_UID=$(id -u ${PG_USER})
USERMAP_ORIG_GID=$(id -g ${PG_USER})
USERMAP_GID=${USERMAP_GID:-${USERMAP_UID:-$USERMAP_ORIG_GID}}
USERMAP_UID=${USERMAP_UID:-$USERMAP_ORIG_UID}
if [[ ${USERMAP_UID} != ${USERMAP_ORIG_UID} ]] || [[ ${USERMAP_GID} != ${USERMAP_ORIG_GID} ]]; then
echo "Adapting uid and gid for ${PG_USER}:${PG_USER} to $USERMAP_UID:$USERMAP_GID"
groupmod -g ${USERMAP_GID} ${PG_USER}
sed -i -e "s|:${USERMAP_ORIG_UID}:${USERMAP_GID}:|:${USERMAP_UID}:${USERMAP_GID}:|" /etc/passwd
fi
}
create_datadir() {
echo "Initializing datadir..."
mkdir -p ${PG_HOME}
if [[ -d ${PG_DATADIR} ]]; then
find ${PG_DATADIR} -type f -exec chmod 0600 {} \;
find ${PG_DATADIR} -type d -exec chmod 0700 {} \;
fi
chown -R ${PG_USER}:${PG_USER} ${PG_HOME}
}
create_certdir() {
echo "Initializing certdir..."
mkdir -p ${PG_CERTDIR}
[[ -f ${PG_CERTDIR}/server.crt ]] && chmod 0644 ${PG_CERTDIR}/server.crt
[[ -f ${PG_CERTDIR}/server.key ]] && chmod 0640 ${PG_CERTDIR}/server.key
chmod 0755 ${PG_CERTDIR}
chown -R root:${PG_USER} ${PG_CERTDIR}
}
create_logdir() {
echo "Initializing logdir..."
mkdir -p ${PG_LOGDIR}
chmod -R 1775 ${PG_LOGDIR}
chown -R root:${PG_USER} ${PG_LOGDIR}
}
create_rundir() {
echo "Initializing rundir..."
mkdir -p ${PG_RUNDIR} ${PG_RUNDIR}/${PG_VERSION}-main.pg_stat_tmp
chmod -R 0755 ${PG_RUNDIR}
chmod g+s ${PG_RUNDIR}
chown -R ${PG_USER}:${PG_USER} ${PG_RUNDIR}
}
set_postgresql_param() {
local key=${1}
local value=${2}
if [[ -n ${value} ]]; then
local current=$(exec_as_postgres sed -n -e "s/^\("${key}" = '\)\([^ ']*\)\(.*\)$/\2/p" ${PG_CONF})
if [[ "${current}" != "${value}" ]]; then
echo "‣ Setting postgresql.conf parameter: ${key} = '${value}'"
value="$(echo "${value}" | sed 's|[&]|\\&|g')"
exec_as_postgres sed -i "s|^[#]*[ ]*${key} = .*|${key} = '${value}'|" ${PG_CONF}
fi
fi
}
set_recovery_param() {
local key=${1}
local value=${2}
local hide=${3}
if [[ -n ${value} ]]; then
local current=$(exec_as_postgres sed -n -e "s/^\(.*\)\("${key}"=\)\([^ ']*\)\(.*\)$/\3/p" ${PG_RECOVERY_CONF})
if [[ "${current}" != "${value}" ]]; then
case ${hide} in
true) echo "‣ Setting primary_conninfo parameter: ${key}" ;;
*) echo "‣ Setting primary_conninfo parameter: ${key} = '${value}'" ;;
esac
exec_as_postgres sed -i "s|${key}=[^ ']*|${key}=${value}|" ${PG_RECOVERY_CONF}
fi
fi
}
set_hba_param() {
local value=${1}
if ! grep -q "$(sed "s| | \\\+|g" <<< ${value})" ${PG_HBA_CONF}; then
echo "${value}" >> ${PG_HBA_CONF}
fi
}
configure_ssl() {
## NOT SURE IF THIS IS A GOOD ALTERNATIVE TO ENABLE SSL SUPPORT BY DEFAULT ##
## BECAUSE USERS WHO PULL A PREBUILT IMAGE WILL HAVE THE SAME CERTIFICATES ##
# if [[ ! -f ${PG_CERTDIR}/server.crt && ! -f ${PG_CERTDIR}/server.key ]]; then
# if [[ -f /etc/ssl/certs/ssl-cert-snakeoil.pem && -f /etc/ssl/private/ssl-cert-snakeoil.key ]]; then
# ln -sf /etc/ssl/certs/ssl-cert-snakeoil.pem ${PG_CERTDIR}/server.crt
# ln -sf /etc/ssl/private/ssl-cert-snakeoil.key ${PG_CERTDIR}/server.key
# fi
# fi
if [[ -f ${PG_CERTDIR}/server.crt && -f ${PG_CERTDIR}/server.key ]]; then
PG_SSL=${PG_SSL:-on}
set_postgresql_param "ssl_cert_file" "${PG_CERTDIR}/server.crt"
set_postgresql_param "ssl_key_file" "${PG_CERTDIR}/server.key"
fi
PG_SSL=${PG_SSL:-off}
set_postgresql_param "ssl" "${PG_SSL}"
}
configure_hot_standby() {
case ${REPLICATION_MODE} in
slave|snapshot|backup) ;;
*)
echo "Configuring hot standby..."
set_postgresql_param "wal_level" "hot_standby"
set_postgresql_param "max_wal_senders" "16"
set_postgresql_param "checkpoint_segments" "8"
set_postgresql_param "wal_keep_segments" "32"
set_postgresql_param "hot_standby" "on"
;;
esac
}
initialize_database() {
if [[ ! -f ${PG_DATADIR}/PG_VERSION ]]; then
case ${REPLICATION_MODE} in
slave|snapshot|backup)
if [[ -z $REPLICATION_HOST ]]; then
echo "ERROR! Cannot continue without the REPLICATION_HOST. Exiting..."
exit 1
fi
if [[ -z $REPLICATION_USER ]]; then
echo "ERROR! Cannot continue without the REPLICATION_USER. Exiting..."
exit 1
fi
if [[ -z $REPLICATION_PASS ]]; then
echo "ERROR! Cannot continue without the REPLICATION_PASS. Exiting..."
exit 1
fi
echo -n "Waiting for $REPLICATION_HOST to accept connections (60s timeout)"
timeout=60
while ! ${PG_BINDIR}/pg_isready -h $REPLICATION_HOST -p $REPLICATION_PORT -t 1 >/dev/null 2>&1
do
timeout=$(expr $timeout - 1)
if [[ $timeout -eq 0 ]]; then
echo "Timeout! Exiting..."
exit 1
fi
echo -n "."
sleep 1
done
echo
case ${REPLICATION_MODE} in
slave)
echo "Replicating initial data from $REPLICATION_HOST..."
exec_as_postgres PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -X stream -w >/dev/null
;;
snapshot)
echo "Generating a snapshot data on $REPLICATION_HOST..."
exec_as_postgres PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -X fetch -w >/dev/null
;;
backup)
echo "Backing up data on $REPLICATION_HOST..."
exec_as_postgres PGPASSWORD=$REPLICATION_PASS ${PG_BINDIR}/pg_basebackup -D ${PG_DATADIR} \
-h ${REPLICATION_HOST} -p ${REPLICATION_PORT} -U ${REPLICATION_USER} -X fetch -w >/dev/null
exit 0
;;
esac
;;
*)
echo "Initializing database..."
PG_OLD_VERSION=$(find ${PG_HOME}/[0-9].[0-9]/main -maxdepth 1 -name PG_VERSION 2>/dev/null | grep -v $PG_VERSION | sort -r | head -n1 | cut -d'/' -f5)
if [[ -n ${PG_OLD_VERSION} ]]; then
echo "‣ Migrating PostgreSQL ${PG_OLD_VERSION} data to ${PG_VERSION}..."
# protect the existing data from being altered by apt-get
mv ${PG_HOME}/${PG_OLD_VERSION} ${PG_HOME}/${PG_OLD_VERSION}.migrating
echo "‣ Installing PostgreSQL ${PG_OLD_VERSION}..."
if ! ( apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql-${PG_OLD_VERSION} postgresql-client-${PG_OLD_VERSION} ) >/dev/null; then
echo "ERROR! Failed to install PostgreSQL ${PG_OLD_VERSION}. Exiting..."
# first move the old data back
rm -rf ${PG_HOME}/${PG_OLD_VERSION}
mv ${PG_HOME}/${PG_OLD_VERSION}.migrating ${PG_HOME}/${PG_OLD_VERSION}
exit 1
fi
rm -rf /var/lib/apt/lists/*
# we're ready to migrate, move back the old data and remove the trap
rm -rf ${PG_HOME}/${PG_OLD_VERSION}
mv ${PG_HOME}/${PG_OLD_VERSION}.migrating ${PG_HOME}/${PG_OLD_VERSION}
fi
if [[ -n $PG_PASSWORD ]]; then
echo "${PG_PASSWORD}" > /tmp/pwfile
fi
exec_as_postgres ${PG_BINDIR}/initdb --pgdata=${PG_DATADIR} \
--username=${PG_USER} --encoding=unicode --auth=trust ${PG_PASSWORD:+--pwfile=/tmp/pwfile} >/dev/null
if [[ -n ${PG_OLD_VERSION} ]]; then
PG_OLD_BINDIR=/usr/lib/postgresql/${PG_OLD_VERSION}/bin
PG_OLD_DATADIR=${PG_HOME}/${PG_OLD_VERSION}/main
PG_OLD_CONF=${PG_OLD_DATADIR}/postgresql.conf
PG_OLD_HBA_CONF=${PG_OLD_DATADIR}/pg_hba.conf
PG_OLD_IDENT_CONF=${PG_OLD_DATADIR}/pg_ident.conf
echo -n "‣ Migration in progress. Please be patient..."
exec_as_postgres ${PG_BINDIR}/pg_upgrade \
-b ${PG_OLD_BINDIR} -B ${PG_BINDIR} \
-d ${PG_OLD_DATADIR} -D ${PG_DATADIR} \
-o "-c config_file=${PG_OLD_CONF} --hba_file=${PG_OLD_HBA_CONF} --ident_file=${PG_OLD_IDENT_CONF}" \
-O "-c config_file=${PG_CONF} --hba_file=${PG_HBA_CONF} --ident_file=${PG_IDENT_CONF}" >/dev/null
echo
fi
;;
esac
configure_hot_standby
# Change DSM from `posix' to `sysv' if we are inside an lx-brand container
if [[ $(uname -v) == "BrandZ virtual linux" ]]; then
set_postgresql_param "dynamic_shared_memory_type" "sysv"
fi
fi
# configure path to data_directory
set_postgresql_param "data_directory" "${PG_DATADIR}"
# configure logging
set_postgresql_param "log_directory" "${PG_LOGDIR}"
set_postgresql_param "log_filename" "postgresql-${PG_VERSION}-main.log"
# listen on all interfaces
set_postgresql_param "listen_addresses" "*"
# allow remote connections to postgresql database
set_hba_param "host all all 0.0.0.0/0 md5"
}
trust_localnet() {
if [[ ${PG_TRUST_LOCALNET} == true ]]; then
echo "Trusting connections from the local network..."
set_hba_param "host all all samenet trust"
fi
}
configure_recovery() {
if [[ ${REPLICATION_MODE} == slave ]]; then
echo "Configuring recovery..."
if [[ ! -f ${PG_RECOVERY_CONF} ]]; then
# initialize recovery.conf on the firstrun (slave only)
exec_as_postgres touch ${PG_RECOVERY_CONF}
( echo "standby_mode = 'on'";
echo "primary_conninfo = 'host=${REPLICATION_HOST} port=${REPLICATION_PORT} user=${REPLICATION_USER} password=${REPLICATION_PASS} sslmode=${REPLICATION_SSLMODE}'";
) > ${PG_RECOVERY_CONF}
else
set_recovery_param "host" "${REPLICATION_HOST}"
set_recovery_param "port" "${REPLICATION_PORT}"
set_recovery_param "user" "${REPLICATION_USER}"
set_recovery_param "password" "${REPLICATION_PASS}" "true"
set_recovery_param "sslmode" "${REPLICATION_SSLMODE}"
fi
else
# recovery.conf can only exist on a slave node, its existence otherwise causes problems
rm -rf ${PG_RECOVERY_CONF}
fi
}
create_user() {
if [[ -n ${DB_USER} ]]; then
case $REPLICATION_MODE in
slave|snapshot|backup)
echo "INFO! Database user cannot be created on a $REPLICATION_MODE node. Skipping..."
;;
*)
if [[ -z ${DB_PASS} ]]; then
echo "ERROR! Please specify a password for DB_USER in DB_PASS. Exiting..."
exit 1
fi
echo "Creating database user: ${DB_USER}"
echo "CREATE ROLE \"${DB_USER}\" with LOGIN CREATEDB PASSWORD '${DB_PASS}';" | \
exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1
;;
esac
fi
}
create_database() {
if [[ -n ${DB_NAME} ]]; then
case $REPLICATION_MODE in
slave|snapshot|backup)
echo "INFO! Database cannot be created on a $REPLICATION_MODE node. Skipping..."
;;
*)
echo -n "Creating database(s): "
for database in $(awk -F',' '{for (i = 1 ; i <= NF ; i++) print $i}' <<< "${DB_NAME}"); do
echo -n "${database} "
echo "CREATE DATABASE \"${database}\";" | \
exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1
if [[ ${DB_UNACCENT} == true ]]; then
echo "CREATE EXTENSION IF NOT EXISTS unaccent;" | \
exec_as_postgres ${PG_BINDIR}/postgres --single ${database} -D ${PG_DATADIR} >/dev/null 2>&1
fi
if [[ -n ${DB_USER} ]]; then
echo "GRANT ALL PRIVILEGES ON DATABASE \"${database}\" to \"${DB_USER}\";" | \
exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1
fi
done
echo
;;
esac
fi
}
create_replication_user() {
if [[ -n ${REPLICATION_USER} ]]; then
case $REPLICATION_MODE in
slave|snapshot|backup) ;; # replication user can only be created on the master
*)
if [[ -z ${REPLICATION_PASS} ]]; then
echo "ERROR! Please specify a password for REPLICATION_USER in REPLICATION_PASS. Exiting..."
exit 1
fi
echo "Creating replication user: ${REPLICATION_USER}"
echo "CREATE ROLE \"${REPLICATION_USER}\" WITH REPLICATION LOGIN ENCRYPTED PASSWORD '${REPLICATION_PASS}';" | \
exec_as_postgres ${PG_BINDIR}/postgres --single -D ${PG_DATADIR} >/dev/null 2>&1
set_hba_param "host replication ${REPLICATION_USER} 0.0.0.0/0 md5"
;;
esac
fi
}
-49
View File
@@ -1,49 +0,0 @@
#!/bin/bash
set -e
PG_VERSION="9.1"
PG_CONFDIR="/etc/postgresql/${PG_VERSION}/main"
PG_BINDIR="/usr/lib/postgresql/${PG_VERSION}/bin"
PG_DATADIR="/var/lib/postgresql/${PG_VERSION}/main"
# fix permissions and ownership of /var/lib/postgresql
chown -R postgres:postgres /var/lib/postgresql
chmod 700 /var/lib/postgresql
# disable ssl
sed 's/ssl = true/#ssl = true/' -i ${PG_CONFDIR}/postgresql.conf
# listen on all interfaces
cat >> ${PG_CONFDIR}/postgresql.conf <<EOF
listen_addresses = '*'
EOF
# allow remote connections to postgresql database
cat >> ${PG_CONFDIR}/pg_hba.conf <<EOF
host all all 0.0.0.0/0 md5
EOF
# initialize PostgreSQL data directory
if [ ! -d ${PG_DATADIR} ]; then
echo "Initializing database..."
PG_PASSWORD=$(pwgen -c -n -1 14)
echo "${PG_PASSWORD}" > /var/lib/postgresql/pwfile
sudo -u postgres -H "${PG_BINDIR}/initdb" \
--pgdata="${PG_DATADIR}" --pwfile=/var/lib/postgresql/pwfile \
--username=postgres --encoding=unicode --auth=trust >/dev/null
fi
if [ -f /var/lib/postgresql/pwfile ]; then
PG_PASSWORD=$(cat /var/lib/postgresql/pwfile)
echo "|------------------------------------------------------------------|"
echo "| PostgreSQL User: postgres, Password: ${PG_PASSWORD} |"
echo "| |"
echo "| To remove the PostgreSQL login credentials from the logs, please |"
echo "| make a note of password and then delete the file pwfile |"
echo "| from the data store. |"
echo "|------------------------------------------------------------------|"
fi
echo "Starting PostgreSQL server..."
exec sudo -u postgres -H ${PG_BINDIR}/postgres \
-D ${PG_DATADIR} -c config_file=${PG_CONFDIR}/postgresql.conf