Install Postgresql8.2.0 from source code under ubuntu 6.06 server

   The Linux distribution used is ubuntu server 6.06. The highest built-in version of ubuntu is only 8.1. In order to try it out, 8.2.0 has improved the compatibility of the windows-based platform to facilitate platform conversion. At the same time, you can customize some parameters and settings for source code installation. Although ubuntu has good ease of use and compatibility, and some of its features are newer, it is somewhat similar to window, which reduces and closes many details, leaving developers no chance. There is no need to try to understand the installation process and parameters of some programs, which is not necessarily a good thing for program development.

 
1. Install Postgresql8.2.0

1. Download the source code.
Go to postgresq.org to download the latest source code.

2 Unzip.
tar -vxf postgresql*.tar.gz
3 configuration, after entering the decompression directory, you can use ./configure –help to view the available parameters. What I use is:

   # ./configure --prefix=/home/shaken/postgresql --without-readline --without-zlib. The

first parameter is to install your own software into the /opt directory as usual, and the next two parameters are This parameter is because readline and zlib are not installed in my system. In fact, just install them.
 
   In Ubuntu, you can remove the following two --without parameters:
   # apt-get install libreadline5-dev zlib1g-dev
  solves the configure problem when installing postgresql on Ubuntu.

4 Compile and install:

  # make

  # make install

5 Add the highest user postgres of the Postgresql database and set the password:

  # adduser postgres
  # mkdir /home/shaken/postgresql/data
  # chown postgres /home/shaken/postgresql/data

It is best to do this:
  # chown -R postgres / home/shaken/postgresql  

6 Log in as user postgres:

  # su – postgres
 
 

7 Initialize the database:
    $ /home/shaken/postgresql/bin/initdb -D /home/shaken/postgresql/data

8 Run the database server:

  $ /home/shaken /postgresql/bin/postmaster -D /home/shaken/postgresql/data>logfile 2>&1 &

9 Create a database:

  $ /home/shaken/postgresql/bin/createdb test

10 Run the client on this machine for management:

  $ /home/shaken/postgresql/bin/psql test

    This requires you to be familiar with basic SQL syntax.

 

    At this point Postgresql is installed. But in order to be able to use the database remotely - for example, if I want to use pgAdmin on another Windows computer on the network to manage and use the Postgresql server - some modifications need to be made. These modifications mainly include two aspects: The first is to modify the two configuration files of Postgresql, and the second is to modify some user permissions of the database:

11 Modify the Postgresql configuration file Postgresql.conf, which is in the data directory /home/shaken/postgresql/data, and change one of the sentences:

listen_address =

Remove the comment in front of 'localhost' and replace 'localhost' with '*'.

 

12 Modify the Postgresql configuration file pg_hba.conf, which is in the data directory /home/shaken/postgresql/data. Add a sentence after the file:

host all all 192.168.0.0/24 password

means: 192.168 in the same network .0.* machines can use all databases in password form. For more specific parameter meanings, just look at the comments in the configuration file.

The configuration must be correct here, otherwise the postgresql database cannot be connected remotely.

 

13 Restart the postgresql server:

 $ /home/shaken/postgresql/bin/pg_ctl stop -D /home/shaken/postgresql/data

  Stop the original server

 $ $ /home/shaken/postgresql/bin/postmaster -i -D /home/shaken/postgresql/data >logfile 2>&1 & Start again,

  add a -I parameter

 

14 Some simple configurations of database user permissions, the following are Use in psql

# create userwen1 password '123456';

 Create a user and set the password

# createdatabase data1 owner wen1;

  Create a database

# create tablewen11(name varcha(10))

  Create a data table

# alter table wen11 owner to wen1;

  Modify data The owner of the table.

  Now you can use other postgresql client tools on other computers in the LAN to open the data1 database with the user name wen1.

 

Some issues that still need to be improved:

1. Issues with Chinese support: Is it good to use encoding='UTF-8' to create a database?

2. The problem of automatically starting postgresql when the system starts: You can refer to the corresponding startup script of Debian.

 
2. Installation and configuration of phppgadmin (optional process)
 
      In order to manage and configure my database server, for a postgresql novice like me, I need a convenient management program. There are many such management tools. Considering that I have a convenient phpmyadmin when using mysql before, I chose phppgadmin. phpPgAdmin is a fully functional internet-based postgresql administration utility. It handles all basic functions and some advanced functions such as triggers, views, etc. It is a management software based on B/S mode and must be installed on the server side.
 
    The specific installation process is:
    1 Download the source code, the latest version is 4.0.1
           # cd
           # wget http://...../phpPgAdmin-4.0.1.tar.gz
       2 Unzip:
      # tar zxvf phpPgAdmin -4.0.1.tar.gz
       3 Check whether the system has installed apache+php and php's support for postgresql. If not, the following is the installation:
      # apt-get install apache php4 php4-pgsql
          Pay attention to modify the apache configuration file to enable apache supports php.
    4. To make phpPgAdmin available on the client, I usually establish a symbolic link in the apapche directory:
      # ln -s /root/phpPgAdmin-4.0.1 /var/www/pgadmin
       5 Modify the configuration file config/config.inc.php of phpPgAdmin. The parameters that must be modified are:
      $conf['servers'][0]['host']='localhost';
           indicates that the database server is on this machine
           $conf ['extra_security'] = false;
           Allow login using postgres account.
    6 Use a browser on the client and enter the address:
      http://.../pgadmin
          to manage the postgresql database.


3. Install postgis

  1. It is best to install proj4 and OGR first. I was lazy and did not install them. It should only be a performance discount and does not affect the installation and use.
   This can be done under Debian: When installing postgis, first:
    #apt-get install proj libgeos libgeos-dev

  2 Download the source code.

  3 Unzip and enter the directory.

  4 Configuration:

# ./configure --prefix=/opt/postgis --with-pgsql=/home/shaken/postgresql/bin/pg_config

The meaning is obvious

  5 Compile and install:

# make

# make install

  6 Some work after:

   $ /home/shaken/postgresql/bin/createdb data1

$ /home/shaken/postgresql/bin/createlang plpgsql data1

$ /home/shaken/postgresql/bin/psql-d data1 -f lwpostgis.sql

$ /home/shaken/postgresql/bin/psql-d data1 -f spatial_ref_sys.sql

Pay attention to find and enter the directory containing the following two sql files and then execute them.

 
Now you can use postgis. First try the two small programs provided by Postgis to convert shape files and postgis data.


4. Preliminary use of PostGIS.

    There are not many articles on the use of PostGIS on the Internet, and they are not detailed enough. After some exploration today, I got some basic application experience, hoping to reduce some of the frustrations for everyone to get started.

    The following assumes that I want to import the data of a test.shp file (actually the complete file should contain three files) into the test data table in the Postgresql database data1. For security reasons, the owners of the database Data1 and related data tables are set. for wen1, and then use this PostGIS data in a GIS client such as QGIS uDig, etc. The detailed process is:

   1 Assume that the PostGreSQL database server and PostGIS are both installed. (See the other article "Source code installation of Postgresql8.1.3+PostGIS1.1.2")
   2 Enter psql as the super user postgres of the database:
     # /home/shaken/postgresql/bin/psql (note the path)
     The following operations are performed in the psql console.
   3 Basic settings:
    # create user wen1 password '123456'; Create a user and set the password
    # create database data1 owner wen1; Create a database
    # alter table spatial_ref_sys owner to wen1;
    # alter table geometry_columns owner to wen1; Modify these two sentences The owner of a postgis-related table is wen1, which is very important. These two points do not seem to be mentioned in general articles.
   4 Data conversion, the following work exits psql and is performed on the shell interface.
     First copy the three test.shp files to the /opt/postgis/bin directory and go to this directory. Pay attention to the path, pay attention to the permissions of the directory and files--it may be easier to exit the postgres user and become the root user.
     # /opt/postgis/bin/shp2pgsql test test data1 > test.sql
     # /home/shaken/postgresql/bin/psql -d data1 -f test.sql
     Note that the parameters must be written correctly. If you don’t understand, be sure to use -- View the help parameter.
   5 Open QGIS on the client machine, select "Layer" --> "Add PostGIS Layer" --> "New", then set the correct server IP, database name data1, user wen1 and password, and then click " "Connect", then the name of the test layer will appear below, just select it.
    The use of uDig is also similar.

    Some experiences:
    1. You must first understand the use of PostgreSQL, especially the concepts and relationships of various permissions, which is generally lacking for people who have transferred from Windows.
    2 It is best to choose a good PostgreSQL client tool to help debug. PgAdmin is recommended.

Guess you like

Origin blog.csdn.net/shaken/article/details/1452329