PostgreSQL is becoming very popular among developers due to its advance features respect to the MySQL which is the most popular opensource .
- This supports the locking mechanism.
- It has high availability.
- It is free and open source software.
- This is ACID compliant.
- It has the capacity for fault tolerance.
- It also supports image, video, audio storage and also supports graphical data.
- It requires very low maintenance.
- It supports Multi-version concurrency control (MVCC).
- Recovery is high.
- It has user defined data-types.
- Table inheritance.
- It runs on all operating systems.
- Windowing functions and analytics (OVER-clause)
- Ordered sets (WITHIN GROUP)
- Hypothetical aggregates (WITHIN GROUP)
- Recursive SQL (WITH RECURSIVE)
- Partial aggregates (FILTER-clause)
- Table sampling
- Parallel queries
- Advanced locking mechanisms
- Many different types of indexes (btree, gist, gin, hash. sp-gist, brin, bloom, etc.)
- Advanced cost-based query optimization
- Partitioned tables
- Synchronous and asynchronous COMMIT
- Synchronous and asynchronous replication
- Quorum commits
- Logical and physical replication
- Partial replication (“CREATE PUBLICATION”)
- High-Availability and auto-failover (with “Patroni”)
- Users, roles, etc.
- Full support for SSL
- Full database encryption (with “Cybertec PostgreSQL_fde”)
- Support for single-sign-on (ActiveDirectory, LDAP, RADIUS, etc.)
- Support for stored procedures in various languages
- Support for custom aggregates
- Professional triggers
Creating and login to PostgreSQL with docker.
postgres - Docker Hub
The PostgreSQL object-relational database system provides reliability and data integrity.
Setup PostgreSQL on Windows with Docker
Over the weekend I finally got the chance to start reading A Curious Moon by Rob Conery which is a book on learning…
$ docker pull postgres$ docker run -d --name node1 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres -p 6551:5432 postgresCheck Whether it is docker container has created as node1$ docker psLogin to the container and run queries$ docker exec -ti node1 bash
$ su postgres
psql (11.2 (Debian 11.2–1.pgdg90+1))
Type “help” for help.
postgres=#// to list all databasespostgres=# \l// command to change the password for the postgres user:postgres=# ALTER USER postgres PASSWORD 'myPassword';// to exitpostgres=# \q
Check whether your PostgreSQL instance has created.
$ docker ps
Connect with the PostgreSQL from Client program.
You can connect with this PostgreSQL server with DBeaver Database management system. Database connection details as follows according to above docker created command. Further it will be required JDBC driver file which you can download from it bellow url.
host : localhost
user : postgres
password : postgres
database : postgres
Download JDBC driver for PostgreSQL.
Binary JAR file downloads of the JDBC driver are available here and the current version with Maven Repository. Because…
Using DBeaver default drivers for PostgreSQL which can be download when the connection creation can be used for the successful connection creation with PostgreSQL server.
Phppgadmin is another web based PostgreSQL client and it can be installed using docker too. Following URL describe the way to do it.
docker run --name=phppgadmin -d --publish=88:80 -e PHP_PG_ADMIN_SERVER_HOST=127.0.0.1 -e PHP_PG_ADMIN_SERVER_PORT=6551 -e PHP_PG_ADMIN_MIN_PASSWORD_LENGTH=0 dockage/phppgadmin:latest
docker run -d -p 12345:80 --link node1:node1 -e "DB_HOST=node1" -e "DB_PORT=6551" --name=postg zhajor/docker-phppgadmin
But i couldn’t connect with locally deployed docker PostgreSQL servers. Anyway web phppgadmin web interface was accessible from both of above methods.
Creating a PostgreSQL cluster
How to Deploy PostgreSQL to a Docker Container Using ClusterControl
Deploying a single PostgreSQL instance on Docker is fairly easy, but deploying a replication cluster requires a bit…
Above web site describe how to create a PostgreSQL . Please check bellow command exicuted to re create a cluster in my server.
// Creatinga a server
$ docker pull postgres// Creating node 1$docker run --name pg_node_1 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres -p 6551:5432 -d postgres// creating node 2
docker run --name pg_node_2 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres -p 6552:5432 -d postgres// Check your containers
$ docker ps// Access the container
Ex : $ docker exec -ti [db-container] bash
$ docker exec -ti pg_node_1 bash
Enable SSH in containers
$ docker exec -ti pg_node_1 bash// update the apt repository
$ apt-get update// Install the openssh client
$ apt-get install -y openssh-server openssh-client// Changing the permission for ssh
$ sed -i 's|^PermitRootLogin.*|PermitRootLogin yes|g' /etc/ssh/sshd_config$ sed -i 's|^#PermitRootLogin.*|PermitRootLogin yes|g' /etc/ssh/sshd_config//start the service
$ service ssh start// change the password
// you can give new password "postgres"Above same steps should be followed to pg_node_2 also.
Start the ClusterControl container (if it’s not started) and forward port 80 on the container to port 5000 on the host:
$ docker run -d --name clustercontrol -p 5000:80 severalnines/clustercontrol// If you have already started containers but down you may see them by
$ docker ps -a
Once done you have to login by web interface.
Then you have to fill a some data and just submit the form.
The last step is setting up the passwordless SSH to all database containers. For this, we need to know the IP Address for each database node. To know it, we can run the following command for each node:
$ docker inspect [db-container] |grep IPAddress"IPAddress": "172.17.0.3",// for windows use following command and search for IPaddress
$ docker inspect172.17.0.3
Then you have to Copy the SSH key to all database containers:
// loging to clustercontrol
$ docker exec -it clustercontrol bash// copy the keys
$ ssh-copy-id 172.17.0.3$ ssh-copy-id 172.17.0.4
You have to select PostgreSQL & TimescaleDB Tab and configure SSH data and database data as follows.
Once it is imported the node will be added to the cluster.