Giter VIP home page Giter VIP logo

postgresql_with_replication's Introduction

๐Ÿ˜ PostgreSQL Replication Project ๐Ÿš€

This project sets up a PostgreSQL replication environment using Docker, with one master node and two slave nodes. It also includes a sample database schema for a store management system.

๐ŸŒŸ Features

  • PostgreSQL 14.5 containers
  • Master-Slave replication with two slaves
  • Sample store database schema
  • Easy setup with Docker Compose
  • Automated backup and initialization scripts

๐Ÿš€ Project Structure

๐Ÿ“ postgresql-replication/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“„ docker-compose.yml
โ”œโ”€โ”€ ๐Ÿ“„ docker-init.sh
โ”œโ”€โ”€ ๐Ÿ“„ createdb.sql
โ”œโ”€โ”€ ๐Ÿ“„ backup-master.sh
โ”œโ”€โ”€ ๐Ÿ“„ create-replica-user.sh
โ”œโ”€โ”€ ๐Ÿ“„ init-slave.sh
โ”œโ”€โ”€ ๐Ÿ“„ init.sh
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ init-script/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ csv/
โ”‚   โ”‚   โ””โ”€โ”€ (various CSV files)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ config/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ pg_hba.conf
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ postgres.conf
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ slave-config/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ slave2-config/
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ init.sh
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ data/
โ”œโ”€โ”€ ๐Ÿ“ data-slave/
โ””โ”€โ”€ ๐Ÿ“ data-slave2/

๐Ÿ›  Setup

  1. Clone this repository: git clone https://github.com/yourusername/postgresql-replication.git cd postgresql-replication

  2. Run the initialization script: ./docker-init.sh

This script will:

  • Clear any existing data
  • Start the master PostgreSQL node
  • Prepare replica configuration
  • Start the slave nodes

๐Ÿณ Docker Containers

  • postgres_master: Master node (Port 5432)
  • postgres_slave: First slave node (Port 5433)
  • postgres_slave2: Second slave node (Port 5434)

๐Ÿ“Š Database Schema

The createdb.sql file sets up a store schema with various tables including manufacturers, categories, products, stores, customers, price changes, deliveries, purchases, and purchase items. It also creates a store_sales_summary view.

๐Ÿ”„ Replication

The master-slave replication is set up automatically using the provided configuration files and initialization scripts:

  • create-replica-user.sh: Creates replication users and replication slots
  • backup-master.sh: Performs base backups for both slave nodes
  • init-slave.sh: Initializes slave configurations
  • init.sh: Orchestrates the entire initialization process

๐Ÿ”’ Security

Replication users are created with encrypted passwords. Ensure to change the default passwords in a production environment.

๐Ÿšง Note

This setup is intended for development and testing purposes. For production environments, please ensure proper security measures are in place and customize the configuration as needed.

postgresql_with_replication's People

Contributors

feliksml avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.