In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you how to start the Ubuntu PostgreSQL database server, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. System environment and installation method
The installation method of Ubuntu PostgreSQL is flexible. You can install it with a source package, a package that comes with your distribution, or an online installation.
1.1 system environment: Ubuntu Linux 7.04; Fedora;Slackware
1.2 installation; installing software under Ubuntu is actually very simple.
Search psql with Synaptic package manager and you will find Ubuntu PostgreSQL-client-8.2 (version 8.1 can be found at the same time), select-apply. Or type xiaop@localhost$ sudo apt-get install Ubuntu PostgreSQL-8.2 Slackware under the terminal to install:
Please go to linuxpackages.net to find the corresponding version of your system, use pkginstall to install, or you install slap-get tools online automatically; to use root permissions, you can use generic sudo. Reference on su and sudo; "Super privilege Control in Linux system" to install Ubuntu PostgreSQL's software package, you can use the following methods
Xiaop@localhost# pkginstall post*.tgz or xiaop@localhost# slapt-get-- install Ubuntu PostgreSQL-8.2.4 in Fedora, you can install it using the package online installation tool. Note: Ubuntu PostgreSQL 8.2 is installed, and the installation will automatically create a default database cluster "main" and generate a database superuser postgres.
two。 Start the Ubuntu PostgreSQL database server
2.1Boot methods for popular Linux distributions
On Ubuntu, the server startup script is placed in the / etc/init.d directory, and you can start it using the following method, which is similar for Fedora and Gentoo
Xiaop@localhost~# / etc/init.d/Ubuntu PostgreSQL-8.2 start Note: start; xiaop@localhost~# / etc/init.d/Ubuntu PostgreSQL-8.2 restart Note: restart; xiaop@localhost~# / etc/init.d/Ubuntu PostgreSQL-8.2 stop Note: stop; xiaop@localhost~# / etc/init.d/Ubuntu PostgreSQL-8.2 status Note: view status
In Slackware, the startup script for Ubuntu PostgreSQL is placed in the / etc/rc.d directory, if you use a package downloaded from linuxpackages.net or installed online; xiaop@localhost~# / etc/rc.d/rc.postgres start if you compile and install with a source package, start Ubuntu PostgreSQL, please check the official Ubuntu PostgreSQL documentation
2.2 about Ubuntu PostgreSQL startup and storage directories
When starting the Ubuntu PostgreSQL server, it is usually started by the postgres user, except for the self-compiled installation; the storage of the database is generally placed in the relevant directory in / var/lib, such as / var/lib/pgsql or / var/lib/Ubuntu PostgreSQL/8.2/main/ directory, etc.; different distributions may be different, but it is still more or less the same. You can change the data storage location to store the database elsewhere.
3. Create a user
Add user command format. Createuser is the encapsulation of the SQL command CREATE USER. Command: createuser [- a] [- A] [- d] [- D] [- e] [- P] [- h hostname] [- p port] username parameter description:
[- a]: allow other users to be created, which is equivalent to creating a superuser; [- A]: do not allow this user to create other users; [- d]: allow this user to create a database; [- D]: do not allow this user to create a database; [- e]: display the execution process on the Shell; [- P]: set a password when creating a user [- h hostname]: create a user for the Postgres on a host; [- p port]: used with the-h parameter to specify the port of the host.
3.1 add users
3.1.1 create users without parameters
Xiaop@localhost~$ createuser testuser Shall the new user be allowed to create databases? (YPop) n-can you create a database: no Shall the new user be allowed to create more new users? (YPO) n-whether you can create a new user: no CREATE USER
Note: when you create a user without parameters, Postgres will ask for the user's permissions. The above example creates a normal user.
3.1.2 create a user for the specified host and port
Xiaop@localhost~$ createuser-h 172.28.18.51-p 5000-D-A-e testuser CREATEUSER joe NOCREATEDB NOCREATEUSER; CREATEUSER
Note: this command creates a user testuser for port 5000 of host 172.28.18.51. This user cannot create databases and other users.
3.1.3 create a superuser
Xiaop@localhost~$ createuser-P-d-a-e testuser Enter password for new user: testuser Enter it again: testuser CREATEUSER joe PASSWORD 'testuser' CREATEDB CREATEUSER; CREATEUSER
Note: this command creates a superuser (- a) locally, creates a database (- d), and requires a password.
3.2 Delete a user:
Command: dropuser [- I] [- h] [- p] [- e] username parameter description: [- I]: request confirmation before deleting the user; [- h hostname]: delete the Postgres user on a host; [- p port]: used with the-h parameter to specify the port of the host; [- e]: display the execution process to the Shell.
3.2.1 deleting a local Postgres user
Xiaop@localhost~$ dropuser testuser DROP USER
3.2.2 deleting a user on a remote Postgres server
Xiaop@localhost~$ dropuser-p 5000-h 172.28.18.51-I-e testuser User "testuser" and any owned databases will be permanently deleted. Are you sure? (YBO) y DROP USER "testuser" DROP USER
Note: this command deletes the user testuser on port 5000 (- p) of host 172.28.18.51 (- h) and requires confirmation (- I)
4. Create and delete databases
4.1 create a database
An example of whether you can access a database server is to try to create a database. To create a new database, called mydb in our example, you can use the following command: xiaop@localhost~$ createdb mydb it should generate the following response: CREATE DATABASE if so, then this step is successful, if you see information like createdb: command not found, then Ubuntu PostgreSQL is not installed, or it is not installed at all
You can also create a database under other names. Ubuntu PostgreSQL allows you to create any number of databases on one node. The database name must start with a letter and be less than 63 characters long. It is convenient to create a database with the same name as your current user name. Many tools assume that the database name is the default database name, so this saves you keystrokes. To create such a database, just type: xiaop@localhost~$ createdb
4.2 Delete the database
If you don't want to use your database anymore, you can delete it. For example, if you are the owner (creator) of the database mydb, you can delete it with the following command: xiaop@localhost~$ dropdb mydb Note: (for this command, the database name is not the default user name. So you have to declare it. ) this action physically deletes all files related to the database and cannot be cancelled, so be sure to think carefully before doing this
5. Access the database
Once you have created the database, you can access it, and you can run a Ubuntu PostgreSQL interactive terminal program called psql, which allows you to interactively enter, edit, and execute SQL commands. (for graphical login, see 6. Ubuntu PostgreSQL graphical management tool pgAdmin3)
5.1 activate the database
You need to start psql to experiment with the example just now. You can activate it for the mydb database with the following command: xiaop@localhost~$ psql mydb if you omit the database name, it defaults to your user account name.
Welcome to psql 8.2.4, the Ubuntu PostgreSQL interactive terminal. Type:\ copyright for distribution terms\ h for help with SQL commands\? For help with psql commands\ g or terminate with semicolon to execute query\ q to quit mydb=# Note: the prompt of * one line mydb=#, means you are a database superuser.
5.2 help and exit the database
The psql program has some internal commands that are not part of the SQL command. They start with a backslash, "\". Some of these commands are listed in the welcome message. For example, you can get help syntax for various Ubuntu PostgreSQL SQL commands with the following command: mydb= >\ h to exit psql, type mydb= >\ Q and psql will quit and return you to the command line shell;. (for more information about internal commands, you can type\? at the psql prompt. )
6. Ubuntu PostgreSQL graphical management tool pgAdmin3; version: Version1.4.3
6.1 installation
6.1.1 Ubuntu installation
There are two ways: 1. Search for pgadmin3 in the Synaptic package manager and find the pgadmin3-- application 2. Input command under the terminal: xiaop@xiaop-laptop:~$ sudo apt-get install pgadmin3
6.1.2 installation of other systems
You can refer to the installation methods of normal software in other systems. Since this is similar, I will not introduce you here.
6.2 simple use of pgAdmin3
The graphical management system is relatively intuitive. You can operate under the command line, and then view the results under pgAdmin3.
6.2.1 launch of pgAdmin3
You can find the startup entry for pgAdmin3 in the application-system tools, or you can enter: xiaop@xiaop-laptop:~$ / usr/bin/pgadmin3 start at the command line
6.2.2 Connect to the created database mydb
Click File-add Server, and then enter under the pop-up window: click OK and you can view the existing database of postsql.
Note: the database of pgAdmin3 and the database created under the terminal are completely synchronized (you can use refresh to view the effect), pgAdmin3 is a more convenient graphical management tool, it can create charts, manage database, etc., we will discuss the details of pgAdmin3 later, this article mainly introduces the operation under the command line. Graphical management tools can do anything on the command line. You can create tables under the command line and check on pgAdmin3 to see if they are synchronized: 7. Create and delete tables
The above is all the contents of the article "how to start the Ubuntu PostgreSQL database server". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.