Sponsored Content
Top Forums Shell Programming and Scripting Setting up postgreSql database Post 302920079 by Helveticus on Tuesday 7th of October 2014 05:14:45 AM
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?
 

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. 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
PAGESIZES(5)							File Formats Manual						      PAGESIZES(5)

NAME
pagesizes - HylaFAX page size definitions DESCRIPTION
The pagesizes database defines the page dimensions and guaranteed reproducible areas (GRA) for well-known page sizes. The GRA is the por- tion of the page that is guaranteed to be imaged during facsimile transmission. This region is typically less than the full page dimen- sions because of paper roller contacts and other mechanical aspects of the printing process in a facsimile machine. All HylaFAX programs that require page size information read the information from this database using a page size name. Documents should be prepared such that the full page dimensions are employed with the imaged area contained within the GRA. The system-wide default page size to use in preparing documents for transmission is given by the ``default'' entry in the database. (NB: the default entry should be placed last so that inverse matches find the real page size name and not the default entry.) The page size database is an ASCII file with the following format. Each entry consists of whitespace-separated fields: name abbrev width height gra-width gra-height top-margin left-margin Fields have the following interpretation: name the full name for the page size; e.g. ISO A4; abbrev an abbreviated version of the full name for use in compact listings such as the receive queue listing printed by faxstat(1); width the full width of the page; height the full height of the page; gra-width the width of the GRA; gra-height the height of the GRA; top-margin the margin between the top of the full page and the top of the GRA; left-margin the margin between the left side of the full page the left side of the GRA. The first two fields must be separated from the subsequent fields by a tab character (possibly followed by more whitespace); this is done to easily permit blank characters to be included in names. Otherwise fields can be separated by any amount of any kind of whitespace. Numbers are all base 10 and in basic measurement units (BMU); defined as 1/1200 x 25.4 millimeters for paper output with a scale factor of one. All fields must be present on a single line; otherwise the entry is ignored. Comments are introduced by the ``#'' character and con- tinue to the end the line. Page size database lookups are either by name or by page dimensions. Lookups by name are done by sequentially scanning the entries in the database for the first entry that has a matching abbreviation or substring of the page size name field. The string comparisons ignore case so, for example, ``a4'' would match a full name of ``ISO A4''. Lookups by dimension scan the entire database and return the page with the closest dimensions using a straightforward distance metric. If the difference in dimensions of the closest match is greater than 1/2 inch on each side, then no page entry is returned for a lookup by dimension. SEE ALSO
hylafax-client(1), faxmail(1), faxstat(1), sendfax(1), sgi2fax(1), textfmt(1). December 5, 1994 PAGESIZES(5)
All times are GMT -4. The time now is 12:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy