Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
PostgreSQL Installation By: Miguel Garzon [email protected] Previous version by Ahmed Jeddah Presentation Overview • • • • • Prerequisite packages Connecting to SITE’s LINUX Server Some basic UNIX commands PostgreSQL Installation PgAdmin III Installation Prerequisite packages • SSH: http://www.ccs.uottawa.ca/download/ssh/ssh329.exe click on the exe file and follow the instructions • PostgreSQL: http://www.postgresql.org/ftp/source/v9.0.0 choose the file postgresql-9.0.0.tar.gz (The version we will be using is ver 9.0.0) • pgAdmin III: http://www.postgresql.org/ftp/pgadmin3/release/v1.8.4/win 32/ choose the .zip file This is only needed if you want to work in your own pc! Connecting to SITE’s LINUX Server • On-Campus: (FTP Server) 1- go to Programs-> SSH Secure Shell -> Secure File Transfer Client --- then click on Quick Connect Connecting to SITE’s LINUX Server Continue: 2- In the host name field : linux.site.uottawa.ca , in the user name field : your site email alias The password: site account password (remember the Autopass) Connecting to SITE’s LINUX Server • Go to Programs-> SSH Secure Shell -> Secure Shell Client --then click on Quick Connect Host name : linux.site.uottawa.ca User name : site email alias Password : site account password Connecting to SITE’s LINUX Server • Connecting Off-Campus -- for connecting to the Secure File Transfer – follow the same steps but Host name: ugate.site.uottawa.ca --for connecting to the Secure Shell – follow the same steps but Host name: ugate.site.uottawa.ca – and then, type: ssh linux.site.uottawa.ca (the server will then ask for a password – it is the same as the site account password) See for more details http://www.site.uottawa.ca/local/labinfo/unix.shtml#2 Some basic UNIX commands • pwd : show the full name of the current directory. – Note that in Unix; we use “/” in the file name description – while in windows we use “\” • mkdir: create a new directory – e.g. mkdir new_folder Note 1: in Unix; Do NOT name directories with a space in them (i.e. A folder called My Documents will cause some problems). Note 2: Unix is case sensitive for commands and files– i.e. Mkdir new_folder is wrong statment Some basic UNIX commands • ls (list files in the current directory) • cd ( current directory) – – – – Examples: cd new_folder (will go to the folder called new_folder) cd ( return to your home directory) cd .. (will go to the parent directory) – Hint: You can use “Tab” when writing the names of directories – it is as Auto Complete ! Some basic UNIX commands • cp : copy a file (or folder) – cp source destination Figure out how it work for folders!! Try typing cp --help to get some help !! • mv : move a file – mv file1 file2 (will move the contents of file1 to file2 – file1 no more exist) Some basic UNIX commands • Removing files and directories: – rmdir: (remove directory) • Note: rmdir cannot remove directory that is not empty – rm: (remove file) – Examples: • • • • rm file1 rm Directory1 ----- Error message: Directory1 is a directory rm --help --- show the documentation of command rm rm –r Directory1 -- No error message (works for files and folders – (Q. What does –r do ?!) • rm –rf File == rm –r –f File --- (Q. What does –f do ?!) • Other Commands – clear : clear the screen – history: display the history of commands Some basic UNIX commands • Compiling a c source code in Linux; – There exist many c compilers: GCC – LCC – PCC – TenDRA. – We are going to use GCC – We don’t need to install it now, it is already there ! Some basic UNIX commands • Compiling C code #include <stdio.h> int main(void) { printf("First file \n"); printf("Hello World \n"); return 0; } Write the following code and save it in hello.c Some basic UNIX commands cd c //c is the directory where hello.c gcc hello.c ls // you will find a file called a.out ./a.out // run executable file ./a.out -bash-3.2$ ./a.out First file Hello World -bash-3.2$ resides Some basic UNIX commands We are not restricted to the file a.out; The statement: gcc hello.c –o b.out will generate the executable file b.out instead, “type gcc -- help for some more useful options;” Some basic UNIX commands Makefile and the make command We can write many commands in a script file and run it all at once; For example: all: gcc hello.c –o b.out mkdir –p x mv b.out x 1) Write the previous commands in a file called Makefile-1.txt; (in the same directory of hello.c); 2) Type the command: make -f Makefile-1.txt Q1. What do this script do ? Q2. What does the –p in mkdir do ? More options in MakeFile all: createFolder first: gcc hello.c -o b.out ./b.out # *** File hello.c Compiled and executed *** createFolder: rm -rf newfolder mkdir newfolder second: gcc second.c ./a.out # *** File calculations.c Compiled and executed *** clean: rm -rf *.out rm -rf newfolder Try these examples and observe the output: make –f makefile-5.txt make –f makefile-5.txt first make –f makefile-5.txt clean make –f makefile-5.txt second make –f makefile-5.txt all More options in MakeFile Rename Makefile-5.txt to Makefile and then run make; i.e. make all ; make clean ; make first etc ... The default file that make look for is Makefile IMPORTANT NOTE: Makefile has NO extension; it is a UNIX file More options in MakeFile • Makefile may be more intelligent and powerful. • We may have variables; (see Makefile-4.txt) • Or we may also use if-else statements (see link: – http://mrbook.org/tutorials/make/ (introduction) – http://theory.uwinnipeg.ca/gnu/make/make_toc. html (more advanced) Installing PostgreSQL 1. Have the file postgresql-9.0.0.tar.gz in your base file (i.e. home/infofa/h/users/you_user_name) 2. Type gzip –d postgresql-9.0.0.tar.gz 3. Type tar zxvf postgresql-9.0.0.tar (Extraction) 3. cd postgresql-9.0.0 Installing PostgreSQL 4) ./configure --prefix=PREFIX --enabledebug –enable-depend Replace PREFIX with the name of the folder you want to install PostgreSQL in; (i.e. /home/infofa/h/users/mgarz042/ postgresql-9.0.0/pgs) --enable-debug and –enable-depend are optional will be useful for the project Installing PostgreSQL 5) gmake // or you may use make “Note” gmake has the same function as make; however; the default file in this case is GNUmakefile make, in this case, points to gmake (Read the file Makefile – intersting) Wait for this message: All of PostgreSQL successfully made. Ready to install. Installing PostgreSQL 6) gmake check This step performs some testing before the installation Expect something like that: ======================= All 114 tests passed. ======================= Installing PostgreSQL 7) gmake install We are done if we see; PostgreSQL installation complete. Installing PostgreSQL 8) Go to directory where you installed PostgreSQL (i.e. PREFIX) cd pgs 9) cd bin 10) ./initdb –D ../data Success. You can now start the database server using: ./postmaster -D ../data or ./pg_ctl -D ../data -l logfile start Installing PostgreSQL 11) Start the server side of the database with ./postgres –D ../data if Error: LOG: could not bind IPv4 socket: Address already in use HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry. WARNING: could not create listen socket for "localhost" FATAL: could not create any TCP/IP sockets then: ./postgres –D ../data –p xxxx // xxxx is any number Installing PostgreSQL DONE !!! You may expect a message like this: LOG: database system was shut down at 2008-10-21 23:34:14 EDT LOG: autovacuum launcher started LOG: database system is ready to accept connections Not Done Yet ! - Open a new terminal window in SSH Secure Shell -Type in the client side: ./psql postgres –p xxxx where xxxx is the same port number of the server side DONE !!! Welcome to psql 8.3.4, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit postgres=# Now, you can write your SQL quiries ! SQL Commands Example of SQL commands; create table products (pnum real); insert into products (pnum, ‘coke’, 1.25); insert into products (pnum, ‘burger’, 5.99); Insert into products (pnum, ‘coffee’, 1.18); Select * from products ; Etc.. int, pname varchar(20), price pname, price) values (12, pname, price) values (13, pname, price) values (551, Installing PgAdmin III • Unzip the file pgadmin3-1.8.4.zip • Follow instructions. This is the same port number the database server is listening to More configurations on PostgreSQL • To connect pgAdmin with PostgreSql: – Go to the directory where the files of the database are located (i.e. in our case: /home/infofa/h/users/ajedd07/postgresql-8.3.4 /data) - Look for #listen_addresses = 'localhost‘ in file postgresql.conf ; change it with listen_addresses = ‘*‘ - At the end of the file pg_hba.conf; add the line 137.122.93.0/32 trust host all all Unfortunatley, even with these changes, pgAdmin can not connect to the database serever from off-campus References PostgreSQL Documentations http://www.postgresql.org/docs/manuals/ pgAdmin III Documentations http://www.pgadmin.org/docs/1.8/index.html Unix commands http://mally.stanford.edu/~sr/computing/basic-unix.html A good reference for c and c++ http://www.cprogramming.com/ PostgreSQL for developpers (useful for the next lectures) http://www.postgresql.org/developer/coding