Setting up postgreSql database


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting up postgreSql database
# 1  
Old 10-07-2014
Setting up postgreSql database

Hi

I have a small bash script which I want to run on an Amazon EC2 Ubuntu instance for setting up a postgreSQL database:

Code:
#!/bin/bash
USERNAME='postgres'
start=$SECONDS
TMP_DIR=/local/test/4g4d
PORT=23456

rm -rf $TMP_DIR/db
mkdir -p $TMP_DIR/

echo "creating database..."
~/postgresql/bin/initdb -D $TMP_DIR/db
if [ $? -ne 0 ]
  then
    echo "Could not create the database"
fi

sed -i "s/#port = 5432/port = $PORT/" $TMP_DIR/db/postgresql.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" $TMP_DIR/db/postgresql.conf
echo "host all all  0.0.0.0/0 md5" >> $TMP_DIR/db/pg_hba.conf

echo "starting postgresql server..."
~/postgresql/bin/pg_ctl -D $TMP_DIR/db -l $TMP_DIR/db/logfile start

if [ $? -ne 0 ]
  then
    echo "Could not start the postgresql server"
fi

sleep 10

echo "creating database..."
~/postgresql/bin/createdb -U $USERNAME -p $PORT asldb

echo "adding schema to database"
~/postgresql/bin/psql asldb -U $USERNAME -f ~/tpch/DBSetup.sql -p $PORT

end=$SECONDS
echo "Time: $((end - start)) secs."

hostname=`hostname`
pid=$$

while [ true ]
do
  echo "writing log..."
  echo `date +"%T"` >> who-$pid@$hostname.log
  echo `date +"%T"` >> top-$pid@$hostname.log
  echo `date +"%T"` >> ps-$pid@$hostname.log
  who >> who-$pid@$hostname.log
  top -n 1 -b >> top-$pid@$hostname.log
  ps aux >> ps-$pid@$hostname.log
  echo "" >> who-$pid@$hostname.log
  echo "" >> top-$pid@$hostname.log
  echo "" >> ps-$pid@$hostname.log
  sleep 10
done

#read -p "Press any key to shutdown server."
# shut server down
#~/postgresql/bin/pg_ctl stop -D $TMP_DIR/db

# delete database
#rm -rf $TMP_DIR

Is this ok? How can I automatically install postgreSQL in a first step (apt-get install...)?

What exactly does the "writting log" loop at the end, i.e. what is logged and where exactly is the log saved?
# 2  
Old 10-08-2014
You should really avoid installing postgreSQL I'd suggest checking it is installed and reporting an issue if not.

The loop at the end of this script never ends as it uses a while [ true ] loop

the loop creates three files :
who-<PID>@<HOST>.log file with output from who command
top-<PID>@<HOST>.log file with output from top command
ps-<PID>@<HOST>.log file with output from ps command
these are written into the current directory and appended every 10 seconds.
# 3  
Old 10-08-2014
Thank you Chubler.

What does output from the who, top and ps command mean, i.e. what will these files contain?
# 4  
Old 10-08-2014
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Setting config database user and password using sed

Hello everybody, I need to modify 200 files using a patern matching, I would like to do it with sed but it's not working with the following syntax: sed -e 's/DATABASE_PASSWORD.*oldpass/DATABASE_PASSWORD__', 'newpass/g' config.php need to find: define("__DATABASE_PASSWORD__", ... (6 Replies)
Discussion started by: dco
6 Replies

2. High Performance Computing

Postgresql Database Corrupt

I am managing a linux cluster which has been build on Platform Cluster Manager PCM 1.2.1) from IBM Platform Computing. Unfortunately somebody deteled data files of postgresql from /var/lib directory. I somehow managed to start the postmaster service again, but all the administrative commands of... (2 Replies)
Discussion started by: ahsanpmd
2 Replies

3. Solaris

Postgresql installation

Hi all, I want to install two postgreql 8.3.5 instances on same servers. already one instalce is running on default port and i need it to be installed on another port.. How ever i achived installing the second instance.. but the problem is if i create a new user using createuser in the newly... (3 Replies)
Discussion started by: phani4u
3 Replies

4. Shell Programming and Scripting

CRON Job to copy database and replace existing database

I have a reseller account with hostgator, which means i have WHM and Cpanel. I have set up a staging environment for one of my wordpress installations (client website), which is essentially sitting at staging.domain.com (live site is at domain.com). The staging website is a complete copy of the... (1 Reply)
Discussion started by: nzrobert
1 Replies

5. Programming

kill - postgresql

Hi guys. I was was designing a simple database in postgresql. I wrote a perl function in postgresql and execute it. suddenly i saw that it is running in an infinite loop. After i stopped executing of the query, i saw that CPU is in 90%+ load. I looked at process list and there it was. postgresql... (1 Reply)
Discussion started by: majid.merkava
1 Replies

6. Shell Programming and Scripting

Script to connect to PostgreSQL database

Hi All, Has anyone of you connected to a remote PostgreSQL database through a shell/perl script. Can you please let me know the steps involed? Thanks. Rahul. (0 Replies)
Discussion started by: rahulrathod
0 Replies

7. UNIX for Advanced & Expert Users

UX Kernel setting while database installation

Hi All I am kinda wondering about the UX kernel parameters, how we configure and why do we configure ???.. especially the 'semaphores'. Could somebody throw some light on this and would really appreciate it. (1 Reply)
Discussion started by: Prince_Charming
1 Replies
Login or Register to Ask a Question