-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
34 lines (30 loc) · 1.47 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
sudo apt-get update -y
sudo apt-get install postgresql -y
sudo sed -i 's/postgres\s*peer/postgres trust/g' /etc/postgresql/**/main/pg_hba.conf
echo "host all all 0.0.0.0/0 md5" | sudo tee -a /etc/postgresql/**/main/pg_hba.conf
# Non-durable settings
# based on http://www.postgresql.org/docs/current/static/non-durability.html
echo "listen_addresses='*'" | sudo tee -a /etc/postgresql/**/main/postgresql.conf
echo "fsync = off" | sudo tee -a /etc/postgresql/**/main/postgresql.conf
echo "synchronous_commit = off" | sudo tee -a /etc/postgresql/**/main/postgresql.conf
echo "full_page_writes = off" | sudo tee -a /etc/postgresql/**/main/postgresql.conf
echo "checkpoint_segments = 30" | sudo tee -a /etc/postgresql/**/main/postgresql.conf
echo "checkpoint_timeout = 1h" | sudo tee -a /etc/postgresql/**/main/postgresql.conf
# Use RAM disk
sudo service postgresql stop
sudo mkdir /tmp/ramdisk;
sudo mount -t tmpfs -o size=128M tmpfs /tmp/ramdisk/;
sudo mv /var/lib/postgresql /tmp/ramdisk/postgresql;
sudo ln -s /tmp/ramdisk/postgresql /var/lib/postgresql;
sudo chmod -R 700 /var/lib/postgresql;
sudo chown -R postgres:postgres /var/lib/postgresql;
sudo service postgresql start;
for i in $(seq 1 5);
do
export database"$i"="werckerdb"$i
export user"$i"="postgres"$i
psql -Upostgres -c "CREATE USER postgres"$i" WITH PASSWORD 'wercker';"
psql -Upostgres -c "CREATE DATABASE werckerdb"$i";"
psql -Upostgres -c "GRANT ALL PRIVILEGES ON DATABASE werckerdb"$i" TO postgres"$i";"
done