Install the PostgreSQL database in Windows

Source: Internet
Author: User
Tags psql postgresql version
Now, when talking about free databases, most people may first think of MySQL. Indeed, MySQL has been applied in many domestic fields, especially in website setup. However, PostgreSQL is actually the most powerful, rich, and complex free database. Many of its features are the predecessor of many commercial databases such as Oracle and DB2.

As a matter of fact, I recently came into contact with PostgreSQL because of the needs of the project. Recently, PostgreSQL has just released version 8.3. I will talk about my installation experience based on the experience of experts on the Internet, learn from new PostgreSQL users.
 
Since PostgreSQL 8.0, it has been officially supported by windows. Before that, if you want to install PostgreSQL on Windows, you must use tools such as cygwin to simulate the Unix environment, therefore, the stability and performance are lower than those installed on Linux. Let's get started.

Download postgresql8.3 for Windows

Log on to the terminal.

 

Start Installation

After downloading the installation file to your local computer, uncompress the package with the decompression tool, and then, like installing other Windows applications, double-click the postgresql-8.3.msi to start the installation wizard.

First, select the language used during installation. In addition, you can select the following options to write the detailed installation log to the current installation directory for troubleshooting. You can also read the installation process.

Select the installation Language

 
Click Next to select the installation content options, which are divided into four parts: database server, user interface, database driver, and development module. You can choose to install as needed. To learn more, I have installed all four parts. .
 

Select installation Option 1

  
 

Select installation option 2

TIPS: If you prefer to use a graphical interface to manage and operate databases, you can choose to install pgadminiii on the user interface.

The next step is service configuration. You can run the database server as a Windows system service, which is also a manifestation of postgresql's true support for Windows installation (for example ).

Select install as a service

 
Set the service name and the Windows account that runs the service. You can enter an existing account or an existing account to allow the installer to automatically create this account.
 

Automatically create an account

After creating an account, you must configure the database listening port, connection license, and local region and super user settings. (Note: I chose "People's Republic of China") the super account created here is a database administrator user. Note the difference with the previous service account. Note that this dialog box appears only when PostgreSQL is selected as a system service in the previous step.
 

Initialize database settings

After you click "Next", a remote connection option will pop up, prompting that the local database connection is acceptable by default. However, if you want the remote computer to connect to the database as well, after installation, set the pg_cmd.conf file separately. The specific settings are described later.

Select the activation process language in the default created Test Database template1. pl/perl requires the installation support of ActiveState Perl 5.8, while PL/Python supports Python 2.3, I only chose pgsql here. Note that this dialog box appears only when PostgreSQL is selected to run as a system service and the database component is initialized.

Select a process Language

Select the activated modules in the test database template1. All the extension files will be installed. This step only selects which modules will be activated by default in all your databases. These extension modules provide some enhanced functions.
 

Select to load the extension module

OK. Now the installation and configuration parameters are complete. You only need to wait for the next step to complete the installation. The PostgreSQL installation speed is extremely fast and varies slightly according to the time of the machine. The installation successful page is displayed.

Start Installation

  
 

Installation End Interface

After restarting, it is found that PostgreSQL 8.1 program groups are added to the Start Menu program, and several processes are added to the task manager, for example.
 

Program menu after installation

Post-Installation Process

Client connection settings

PostgreSQL rejects connections from all remote clients by default for security reasons. If you want to remotely log on to the server, you need to set pg_assist.conf, choose Start> program> PostgreSQL 8.1> configuration files to edit pg_cmd.conf.
 

Edit pg_cmd.conf

Modify to the following content:
# IPv4 local connections:
Host All all 127.0.0.1/32 MD5
Host All all 192.168.9.226/32 MD5

This means that the local machine and 192.168.9.226 can connect to the database through an MD5 encrypted password. By modifying the IP address mask, you can also allow the IP address segment to connect to the server. In addition, the authentication method MD5 can also be changed to trust, indicating that the connection to this address is fully trusted (this is more convenient when debugging the program ). Change to password, indicating that the password is connected by the password, but the password is sent in plaintext. After the configuration is complete, you need to restart PostgreSQL to take effect.

Client connection test

After the above installation and setup, a simple PostgreSQL database server has been established. Next we will look at how we can implement the following tasks on this database server: 1. create and delete a database. 2. create or delete a table.

The preceding installation process allows you to access and operate databases in two ways.
Psql to ipvs
From the Start menu --> program --> PostgreSQL 8.1 --> Psql to S, enter the password of the superuser specified during installation, as shown in figure
 

Enter Password

Enter the password and go to the command line interface.
 

Psql operation interface

Enter create database mydb; Create a database mydb; drop database mydb to delete the database mydb you do not want;

Use create table myfirsttb (firstcol integer, secondcol text); Create a table myfirsttb, and drop table myfirsttb; Delete table myfirsttb.

For more commands, go to the http://www.pgsqldb.org to query related documents.
Use pgadmin to manage databases
Choose Start> program> PostgreSQL 8.1> pgadmin III, as shown in figure
 

Graphical interface

Right-click PostgreSQL database server 8.1 (localhost: 5432) and click Connect. Because I set a local connection in pg_hba.conf and use a password, the following dialog box is displayed.
 

Enter the superuser password window

Enter the superuser password to enter the graphical Management Interface
 

Graphical Management Interface

You can easily and intuitively manage databases here.
In addition, you can use other image management tools to manage and operate PostgreSQL databases. For example, you can use EMS PostgreSQL Manager (which must be later than 2.7 to support postgresql8.0) for management.

From the installation process, installing PostgreSQL on Windows is already a very simple task. Just like the author, you can install PostgreSQL in the Wizard, you can install it without administrative permissions. This is a PostgreSQL version that supports windows (without cygwin). PostgreSQL is installed as a service and can be started after the machine is restarted.

PostgreSQL has very low minimum resource requirements. For example, if you open the web browser and MS-word during remote connection, you can see that the test machine is not affected.

If there are deficiencies, since PostgreSQL users are not as widely used as mysql users, the online discussion forum is not very active and it is an obstacle for beginners to get started. I believe this will gradually improve.

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.