In this article, we will focus on another option, the open source database named PostgreSQL. Although MySQL is a fast, powerful, and fairly simple relational database management system, PostgreSQL is more comprehensive and sacrifices some speed for this complexity.
If you are used to using interfaces that contain various icons and shortcuts, PostgreSQL is very suitable for you, although MySQL 4 provides similar functions. To clearly illustrate how to build PostgreSQL in this article, I use the following software: Red Hat Linux 7.1 PostgreSQL 7.1.3
Prepare for Installation
You need to get the software before you start. You can download the latest version 7.1.3. After downloading the PostgreSQL source code program, put it in the/usr/local directory of the Linux server. If you place it elsewhere, specify and modify the corresponding path indication.
PostgreSQL does not run with root permissions. This comes from the developer's security design philosophy. Therefore, you need a user account to establish and run the PostgreSQL process. In this article, we use the postgres user and create a group named postgres.
Of course, if you want to create these accounts, You need to log on as a Super User (usually root permission ). To create this S user group on a Linux server, I will execute groupadd postgres in the command line. Next, create a user and join the group. Run the command "useradd S-g postgres.
Before we officially start to install PostgreSQL, we still need to do two things. First, we will create the directory we will use and specify the owner in postgres. In this way, you can avoid problems caused by unclear permissions.
First, create two directories: mkdir/usr/local/pgsql mkdir/usr/local/postgresql-7.1.3
Then, specify the owner of these two directories in the postgres user created earlier: chown postgres. postgres/usr/local/pgsql chown postgres. postgres/usr/local/postgresql-7.1.3
Now let's decompress this version so that you can install it. First, run the su postgres command to change the postgres user. Then, run the cd/usr/local command to go to the/usr/local directory and unzip the downloaded file with the following command: gunzip-dc postgresql-7.1.3.tar.gz | tar xvf
After the files in the list are decompressed, you will return to the command prompt and use the cd/usr/local/postgres-7.1.3 command to go to the corresponding directory.
After that, you can start.
Like other open-source programs, the first step in the installation process is to specify your operating environment in the installation configuration, including the desired program installation path and the specific performance is valid/invalid.
For the purpose of installation, we need to be sure that the software is installed in the/usr/local/pgsql Directory, which is the directory we previously created. To complete this step, run the command:./configure -- prefix =/usr/local/pgsql.
The next step is to compile the source program with the options provided previously. Use the command line to achieve this. After installation, you can run the command to install the binary file.
Wait, there are more
Before you start the database, PostgreSQL also needs to set some environment variables. You should let PostgreSQL know where to find its data files, shared libraries, application files, and Operation Records.
. On my RedHat Linux 7.1 server, I like to implement this by modifying the. bash_profile file in the/home/postgres directory. Because this file is viewed during login, you can add appropriate variables for the postgres user in the environment. Use your favorite text editor to complete the following steps (I use pico ).
Run the following command to open and edit the. bash_profile file: Pico/home/Postgres/. bash_profile.
Then, add the following lines before the username line in the file: pglib =/usr/local/pgsql/lib pgdata =/usr/local/pgsql/data path = $ path: /usr/local/pgsql/bin manpath = $ manpath:/usr/local/pgsql/man export pglib pgdata path manpath
Save the file and run the following command to create the directory/usr/local/pgsql/pgdata: mkdir/usr/local/pgsql/data.
If the Postgres user has full permissions on the entire/usr/local/pgsql directory, you do not need to use the root user. This directory stores all your database files.
Start your (database) Engine
Before you can officially start the database engine, you need to use an initialization command to initialize different PostgreSQL databases. To implement this initialization, run the command CD/usr/local/pgsql/bin, type./initdb, and then press [enter]. You will get a lot of status information and return to the command line prompt.
At this time, you can use the following command to enable ipvs Postmaster:/usr/local/pgsql/bin/postmaster-I-d/usr/local/pgsql/Data &
This will start PostgreSQL and run the database in the/usr/local/pgsql/data directory. You can connect the database from the Internet (through the parameter-I ), it can run in the background (through Parameters &). Your database engine has been started and is ready to accept data.
Create a database
In this example, we will create a database named mydb and a table named mytable, so that you can be sure everything works properly. First, type createdb mydb in the command line. If PostgreSQL replies to the created database, the command is accepted. Now, we use the psql tool to work with this database. Type psql mydb and press [Enter]. This will take you into the interactive mode of PostgreSQL.
To create a mytable table in the mydb database, follow these steps. Remember that this is not a real TABLE, but a sample: create table mytable (id varchar (20), name varchar (30 ));
Once you complete this, you will see a CREATED information, indicating that the table has been CREATED. Now we can INSERT a record in the table, view the content, and exit the psql tool: insert into mytable values (writer, Scott Lowe );
Now psql will reply to INSERT 18732 1. To view the content of this table, type: SELECT "* from mytable ;"
You will see the following results:
Identity | Name
-------- + ------------
Writer | Scott Lowe
To exit the psql tool, type/q and press [Enter].
Summary
This gives us a general idea of the Basic installation process of PostgreSQL 7.1.3 database on RedHat Linux. I think you will see that PostgreSQL is a powerful database and runs smoothly in multiple environments with its advanced performance.
If you encounter any problems when installing PostgreSQL, I suggest you carefully read the documentation on the PostgreSQL Web site. (Translation: Zhi de; responsible editor: Liu yanzhi)
Techrepublic is an online community and resource center designed for various IT professionals. We provide in-depth technical articles written by IT experts to address it expert readers. In addition to Windows, e-mail, firewall, and other articles, we also provide IT industry analysis, downloads, management points, discussion groups, and news and email services.
From: ZDnet China