This repository stores Ansible codes of my PGConfEU 2015 talk (Presentation).
This Ansible playbook:
- Provisions Amazon VPC and Amazon EC2 instances
- Installs latest PostgreSQL packages
- Configures a streaming replication with 1 master and 2 standbys
Ansible and the Boto package is required to run this playbook.
apt-get install python-dev python-setuptools
easy_install pip
pip install ansible botoSee this in action.
sudo easy_install pip
sudo pip install ansible boto- Clone this repo
git clone https://github.com/gulcin/pgconfeu2015.git - Edit
~/.bototo provide AWS access credentials
[Credentials]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY- [optional] Edit
~/.ansible.cfgto disable host key checks
[defaults]
host_key_checking = FalseYou can skip this step, however Ansible will first ask you about a confirmation to connect to new created hosts.
You can run this playbook simply by using the ansible-playbook command.
ansible-playbook -i hosts.ini main.ymlSee this in action
We can see details about provisioned AWS EC2 instances by using the AWS Command Line Interface.
First time installation and configuration of awscli is required.
sudo pip install awscliAfter installing awscli you can configure it and provide your AWS credentials:
aws configureTo see created instances with their public IP addresses, you can issue the following command:
aws ec2 describe-instances --no-paginate --output=text \
--filters 'Name=instance-state-name,Values=running' \
--query 'Reservations[].Instances[].[Tags[?Key==`Name`].Value, PublicIpAddress]' \
| sed '$!N;s/\n/ /' | grep pg | sort -k2You can also check if the replication is working correctly with a scenario like this:
-
Connect to the master instance
ssh ubuntu@<IP_ADDRESS>
-
See if PostgreSQL processes are running
ps axw | grep "postgres:"
-
Change to the
postgressystem usersudo su - postgres
-
Connect to the
viennadatabasepsql vienna
-
Create a test table
CREATE TABLE test (title text);
-
Insert some data to this table
INSERT INTO test VALUES ('Test row 1'); INSERT INTO test VALUES ('Test row 2'); INSERT INTO test VALUES ('Test row 3');
-
-
-
Connect to standby instances
ssh ubuntu@<IP_ADDRESS>
-
See if PostgreSQL processes are running
ps axw | grep "postgres:"
-
Change to the
postgressystem usersudo su - postgres
-
Connect to the
viennadatabasepsql vienna
-
Check the recovery status:
SELECT is_in_recovery(); -
Select some data from the test table
SELECT * FROM test;
-
-
You can find Asciinema videos shown in my presentation here