Install Postgresql in Ubuntu source code

Source: Internet
Author: User
Tags postgresql version
Environment: Operating system: UbuntuServer10.10Postgresql version: 8.4.51. switch to the ROOT account, create the Softwares directory under the ROOT directory, and grant the corresponding permissions. 2. download Postgresql8.4.5wgethttp: // logs /...

 

Environment: Operating system: Ubuntu Server 10.10 Postgresql version: 8.4.51. switch to the ROOT account, create the Softwares directory under the ROOT directory, and grant the corresponding permissions

2. download Postgresql 8.4.5
Wget http://wwwmaster.postgresql.org/redir/391/f/source/v8.4.5/postgresql-8.4.5.tar.gz

Download the postgresql-8.4.5.tar.gz file in the current directory.

 

Then decompress the file using the tar command.

tar vxf ./postgresql-8.4.5.tar.gz

After decompression, you will see the postgresql-8.4.5 directory in the current directory, which has the following files

Before installation, you must make some settings. first, install two library files: libreadline5.dev and zlib1g. dev.

    sudo apt-get install libreadline5-dv    sudo apt-get install zlib1g-dev

After the Postgresql environment is compiled, execute the following commands in sequence:

./configure --prefix=$PostgresqlPath    make    make install

Note: $ PostgresqlPath indicates the installation directory of your specified Postgresql, such as/softwares/postgresql.

After a long compilation and installation, we will see the installation directory under the specified directory.

      cd $PostgresqlPath/bin

Go to the Bin directory under the Postgresql installation directory, create a directory for storing database files named PGDATA, and create a directory named S s under this directory, create a user named S (specifically used to operate databases) and assign the owner of the postgres directory to it.

After completing the preceding operations, switch to postgres and enter the $ PostgresqlPath/bin directory. execute the following command to initialize the Data Directory:

./initdb -D PGDATA/postgres

After initialization and creation, the following message is displayed:

You can run the following two commands in the prompt to start the database:

 ./postgres -D PGDATA/postgres

By now, the database named as the user you created has been started. you can use pgsql to operate it. To enable the database to start when it is started, we can set it to start when it is started. First, we need to confirm the running level of the current Ubuntu.RunlevelCommand

 

From this we can see that N 2 indicates that the running level of the current UT is 2. we need to set the startup item in rc2.d under The etc directory.

Go to the rc2.d directory and see the list shown in. we need to add the Postgresql startup command in S03rc. local. Here we need to explain the S03rc. local file command: We can see that most of the file names in this directory areS + number + file nameComposition,SIndicates that the file is executed when it is started.KThe file at the beginning indicates that it is not running at startup, which is similar to starting or stopping a service in Windows.NumberIndicates the running priority. the larger the number, the higher the priority. We use VI to edit S03rc. local:

Add the following code to the arrow:

su -c "/softwares/postgresql/bin/pg_ctl start -D /softwares/postgresql/bin/PGDATA/postgres" postgres

Save and exit file editing. don't rush to restart the test. First, you need to change the Ubuntu Shell settings. from Ubuntu 6.0 or above, Shell is changed from the original Bash to a smaller Dash, the latter is smaller and more efficient than the former, but some shells that previously supported Bash cannot run in Dash. Therefore, we recommend that you switch it back to Bash. The procedure is as follows:

Type: sudo dpkg-reconfigure dash

 

Select "No" on the above page. the following page is displayed:

 

We can find that ubuntu deletes the link pointing to dash and adds the bash link and library.

Now we have configured Postgresql on Ubuntu. let's use shutdown-r now to restart Ubuntu and try to start Postgresql at startup.

 

Author ??? Shard fragments

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.