tutorial on installing PostgreSQL on Mac os _postgresql

Source: Internet
Author: User
Tags install brew mysql in postgresql tar xz git clone

Let me start with a bit of chatter. I've been working happily with MySQL, a time-tested old friend. But since the understanding of a little PostgreSQL, it is fascinated by its rich functional characteristics. For example, field types natively support JSON, XML, and array. Compared with MySQL, feel PostgreSQL more advanced.

Install Brew

Official documents:
http://mxcl.github.com/homebrew/
First install git, open a shell:

Cd/usr/local
sudo mkdir homebrew
curl-l https://github.com/mxcl/homebrew/tarball/master | sudo tar xz--strip 1 -C Homebrew
CD Homebrew/bin
./brew-v
file Brew
cat Brew | moresudo./brew UPDATE

If the Brew Update command performs an error, make sure that the owner permission for the folder/usr/local is you and not the root:

sudo chown $USER/usr/localbrew updat

Update path configuration in '. Bash_profile '
(if ~ does not have a file ". Bash_profile" please perform: Touch '. Bash_profile ')

Vim '. Bash_profile '

Join

Export path= $PATH:/usr/local/homebrew/bin

You can then execute brew directly (No./brew)
If you have git you can install it like this (not tested)

git clone https://github.com/mxcl/homebrew.git
CD homebrew/bin
cd homebrew/bin
./brew-v

Installation test

./brew install wget
./brew uninstall wget
./brew searc/apache*/

Install PostgreSQL

Use Brew to get a handle on it.

Brew Install Postgres

Initializing the database

Initdb/usr/local/var/postgres

Start or stop a database

To start the service:

pg_ctl-d/usr/local/var/postgres-l/usr/local/var/postgres/server.log Start

Stop service:

pg_ctl-d/usr/local/var/postgres stop-s-M fast

If trouble first, you can join the boot automatically start

Ln-sfv/usr/local/opt/postgresql/*.plist ~/library/launchagents

Common operations

1. Create a PostgreSQL user

CreateUser username-p
#Enter password for new role:
#Enter it again:

The above username is the user name, enter 2 times the user's password, the user created complete. More user-created information can be viewed "CreateUser--help".

2. Create a database

Createdb Dbname-o username-e utf8-e

The above creates a database named dbname, and specifies that username is the owner (owner) of the database, and that the encoding (encoding) of the database is UTF8, and that the parameter "-e" means that the command to perform the operation of the database is displayed.

More database creation information can be viewed "createdb--help".

3. Connecting to the database

Psql-u username-d dbname-h 127.0.0.1

Experience

Still in the study, generally feel that the difference is not the same as MySQL, are the implementation of the standard SQL statements. Limit statements are now found to be different from MySQL. For example, MySQL to take the first 10 records:

SELECT * FROM table limit 0, 10

In the PostgreSQL, it is:

SELECT * FROM table limit offset 0

In this way, I think the PostgreSQL looks clearer. MySQL in the offset is optional, familiar with the use of the future, it is very easy to start at the time of the offset and limit value of the position.

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.