Since the acquisition of MySQL by Oracle, PostgreSQL becoming the preferred source relational database. This article describes the installation and basic usage of PostgreSQL, for first-time users get started. The following Debian-based operating systems, other operating systems is no energy balance, but most of the content should be generally applicable. First, the installation First, install the PostgreSQL client. sudo apt-get install postgresql-client Then, install PostgreSQL server. Under sudo apt-get install postgresql normal circumstances, after the installation is complete, PostgreSQL server will automatically open in 5432 port of this machine. If you want to install a graphical management interface, you can run the following command, but the article does not cover this aspect. After Nike Air Max sudo apt-get install pgadmin3 Second, Air Jordan Outlet add new users and new database is first installed, default creates a database named postgres and database user named postgres's. It should be noted that, while also generating a Linux system user named postgres's. Here, we use the postgres user to generate other users and new databases. Several methods can achieve this, Here are two. The first method, using PostgreSQL console. First, create a new Linux user, Women Nike Air Yeezy II you can get 2015 Nike Free 5.0 the name you want, here dbuser. sudo adduser dbuser then switch New Nike Tr Fit Shoes Black Navy to the postgres user. sudo su - postgres Next, log PostgreSQL console psql command. User postgres psql then equivalent to the same name as the database user, login to the database, which is not to enter a password. If all goes well, the system prompt changes to 'postgres = #', represents this time has entered the database console. The following commands are completed in the console. The first thing is to Nike Zoom KD V use the \\ password command to set a New Nike Free 5.0 V4 Shoes Black Red password for Air Max 2012 Black Red White the postgres user. \\ Password postgres second thing is to create a database user dbuser (just created a Linux system users), and set a password. CREATE USER dbuser WITH PASSWORD 'password'; the third thing is to create the user database, here exampledb, and specify an owner for dbuser. CREATE DATABASE exampledb OWNER dbuser; fourth thing is that all the permissions are given exampledb database dbuser, otherwise dbuser can only login to the console, there is no database operating authority. GRANT ALL PRIVILEGES ON DATABASE exampledb to dbuser; Finally, \\ q command to exit the console (you can also press ctrl + D). \\ Q The second method, using the shell command line. Add new users and new database, except in the PostgreSQL console, you can New Nike Free Run 3 Shoes Women Grey Purple Womens also complete at New Nike Tr Fit Running Shoes Black the shell command line. This is because PostgreSQL provides a command-line program createuser and createdb. Or to create a new user dbuser and database exampledb example. First, create a database user dbuser, and designated it as the root user. sudo -u postgres createuser --superuser dbuser Then, log database console, set dbuser user's password, exit the console when finished. sudo -u postgres psql \\ password dbuser \\ q Then, at the shell command line, create the database exampledb, and specify an owner for dbuser. sudo -u postgres createdb -O dbuser exampledb Third, after logging database to add new users and new database, the name of the new user must log into the database, then use the psql command. psql -U dbuser -d exampledb -h New Nike Tr Fit Shoes Black Red 127.0.0.1 -p 5432 command above meaning of the parameters are as follows: -U specified user, -d specify the database, -h specify the server, -p designated ports. Enter the above command later, the system prompts the user dbuser password. Enter the correct, you can log consoles. psql command shorthand exist. If the current Linux system users, but also PostgreSQL user, you can omit the user name (part -U argument). For example, my Linux system user name ruanyf, and PostgreSQL database user name already exists, then after I logged in to ruanyf Linux system, you can directly use the following command to log database, and Air Max 2012 Blue Silver White does not require a password. psql exampledb In this case, if there are internal PostgreSQL database with the same name as the current system user, then even the database name can be omitted. For example, assume there is a known ruanyf New Nike Free 5.0 V4 Shoes Black Blue database, you simply type psql you can log on to the database. psql In addition, if you want to restore external data, you can use the following command. psql exampledb \u0026 lt; exampledb.sql four console commands used in addition to already \\ password command outside (password) and \\ q command (quit), the console also offers a range of other commands. \\ H: See explanation of SQL commands, Air Max 2012 Blue Silver White such as \\ h select. \\ ?: See psql command list. \\ L: List all databases. \\ C [database_name]: connect to other databases. \\ D: List all the current table database. \\ D [table_name]: Lists Nike Air Max 2011 the structure of a piece of the table. \\ Du: Lists all users. \\ E: Open a text editor. \\ Conninfo: list database and information on the current connection. Five basic database operations database operation is to use general SQL language. # Create a new table CREATE TABLE usertbl (name VARCHAR (20), signupdate DATE); # insert data INSERT INTO usertbl (name, signupdate) VALUES ('Joe Smith', '2013-12-22'); # select the record SELECT * FROM user_tbl; # update data UPDATE user_tbl set name = 'John Doe' WHERE name = 'Joe Smith'; # delete records DELETE FROM user_tbl WHERE name = 'John Doe'; # add fields ALTER TABLE user_tbl ADD email VARCHAR (40) ; # update structure ALTER TABLE usertbl ALTER COLUMN signupdate SET NOT NULL; # renamed column ALTER TABLE usertbl RENAME COLUMN signupdate TO signup; # Delete Field ALTER TABLE user_tbl DROP COLUMN email; # table renamed ALTER TABLE usertbl RENAME TO backuptbl; # Delete table DROP TABLE IF EXISTS backup_tbl; (End)PostgreSQL Getting Started