In this article, we will pay attention to another option, named PostgreSQL open source database. Although MySQL is a fast, powerful and fairly simple relational database management system, POSTGRESQL is more comprehensive, and some speeds have been sacrificed for this complexity.
If you have become accustomed to using interfaces that contain various icons and shortcuts, PostgreSQL is ideal for you, although the 4 versions of MySQL also provide similar features. In order to clearly explain how to create PostgreSQL in this article, I use the following version of the software: Red Hat Linux 7.1 PostgreSQL 7.1.3
Preparation installation
Before you start, you need to get these software. You can download the latest version 7.1.3. After downloading the POSTGRESQL source program, you should put it in the / usr / local directory of the Linux server. If you put it elsewhere, please specify and modify the corresponding path indication.
PostgreSQL does not run in root permissions. This is from the developer's security design idea. Therefore, you need a user account to create a running postgreSQL process. In this article we use the Postgres user, and will also create a group called Postgres.
Of course, if you want to create these accounts, you need to log in as superuser (usually root permissions). In order to create this Postgres user group on the Linux server, I will execute GroupAdd Postgres in the command line. Next, create a user and join this group, command to use UserAdd Postgres -G Postgres.
We also need to do two things before you officially start installing postgreSQL. First, we will create themselves to use the directory to be used and specify the owner in the Postgres user. This will avoid the problem brought by the unclear.
First, create two directories: mkdir / usr / local / pgsql mkdir /usr/local/postgreSQL-7.1.3
Then, specify the owner of the Postgres user created earlier: chown postgres.postgres / usr / local / pgsql chown postgres.postgres /usr/local/postgreSQL-7.1.3
Let us now decompress this version so you can install it. First, change the Postgres user with the sustgres command. Then, use the CD / USR / LOCAL command to the / usr / local directory and use the following command to extract the downloaded file: gunzip -dc postgreSQL-7.1.3.tar.gz | tar xvf
When the file in the list is decompressed, you will return to the command prompt, use the CD /us R / OCAL/POSTGRES-7.1.3 command to the corresponding directory.
After completing, 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 specific performance effective / invalid.
In order to implement the installation, we must confirm that the software is installed in the / usr / local / pgsql directory, this is the directory we have previously created. In order to complete this step, we use the command: ./configure --prefix = / usr / local / pgsql
The next step is to compile the source program with previously provided options. Use the command line to implement this. After completing, you can install binary files by typing the command.
Take a moment, there are more
Before you start the database, PostgreSQL also has some environment variables that need to be set, you should let PostgreSQL know where it can find its data file, shared library, application file, and operation record. On my Redhat Linux 7.1 server, I like this by modifying the .bash_profile file under the / home / postgres directory. Since this file is viewed when logging in, you can add a suitable variable to the Postgres user in the environment. Use your favorite text editor to complete the following steps (I use Pico).
Use the following command to open and edit .bash_profile file: Pico /HOME/Postgres/.bash_profile
Then, add the following list before the user name 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 create a directory with the following command / usr / local / pgsql / pgdata: MKDIR / USR / local / PGSQL / DATA
If Postgres users have full permissions to the entire / usr / local / pgsql directory, you don't need to use root users. This directory will store all your database files.
Start your (database) engine
Before you can formally launch the database engine, you need to initialize different PostgreSQL databases through a initialization command. If you want to implement this initialization, use the command cd / usr / local / pgsql / bin and type ./initdb, then press [ENTER]. You will get a lot of status information and return to the command line prompt.
At this moment, you can use the following command to open postgres 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, which can be connected to the database (pass parameter -i) on the Internet, which can be run in the background (pass parameter &). Your database engine has started and started to prepare data.
Create a database
In this example, we will create a database called MyDB and a table named myTable, which makes you confident that everything works normally. First, type createdb mydb in the command line. If PostgreSQL replys CREATED DATABASE, the command has been accepted. Now we use the PSQL tool to work together with this database. Type PSQL MyDB and press [ENTER]. This will take you into the interactive mode of PostgreSQL.
If you want to create a MyTable table in the MyDB database, you can follow the steps below. Remember this is not a real form, just a sample, Create Table myTable (ID varchar (20), name varchar (30));
Once you finish these, you will see a created message, indicating that the form is already created. Now we can insert a record in the table, view the content, and then exit the PSQL tool: Insert Into MyTable Values (writer, Scott Lowe);
Now PSQL will reply to INSERT 18732 1. If you want to view the content of this form, type: select "* from myTable;"
You will see the following results:
Identity | Name -------- ----------
Writer | Scott Lowe
If you want to exit the PSQL tool, type / q and press [Enter].
to sum up
This allows us to roughly understand the basic installation process of PostgreSQL 7.1.3 database on Redhat Linux. I think you will see PostgreSQL is a powerful database that is fully capable of running in a variety of environments with its advanced performance.
If you encounter any problems while installing PostgreSQL, I suggest you read the documentation in the PostgreSQL Web site. (Translation: Zhid; Responsible Editor: Liu Yan)
TechRepublic is an online community and resource center designed for various IT professionals. We offer a deep technical article, which is written by IT experts, facing IT expert readers. In addition to providing various articles such as Windows to E-mail to firewall, we also provide IT industry analysis, download, management points, discussion groups, and newsmail services.
From: ZDNET China