`
sillycat
  • 浏览: 2487695 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

PostgreSQL(1)Setup PostgreSQL DB

 
阅读更多

PostgreSQL(1)Setup PostgreSQL DB

I know the related things as follow:
cassandra DB, mongo DB, redis DB
Kafka, zookeeper, rabbitMQ, spark.

I begin to learn to know about the PostgreSQL.

1. Installation
Install that on my local MAC OS from here http://www.enterprisedb.com/products-services-training/pgdownload#osx

What I got is here http://get.enterprisedb.com/postgresql/postgresql-9.3.4-1-osx.zip

Double click and install on my machine. Not good for me.

Install from Source
http://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.gz

>tar zxvf postgresql-9.3.4.tar.gz
>cd postgresql-9.3.4
>./configure --prefix=/Users/carl/tool/pgsql-9.3.4
>make world
>make install-world

Make the soft link
>sudo ln -s /Users/carl/tool/pgsql-9.3.4 /opt/pgsql-9.3.4
>sudo ln -s /opt/pgsql-9.3.4 /opt/pgsql

>vi ~/.profile
export PATH=/opt/pgsql/bin:$PATH

>. ~/.profile

Verify the Installation
>postgres --version
postgres (PostgreSQL) 9.3.4

2. Prepare the Databases
>mkdir -p /Users/carl/db/postgresql

Initial the DB 
>initdb --pgdata=/Users/carl/db/postgresql
Success. You can now start the database server using:    postgres -D /Users/carl/db/postgresql or    pg_ctl -D /Users/carl/db/postgresql -l logfile start

Check status
>pg_ctl -D /Users/carl/db/postgresql status

Start the server
>pg_ctl -D /Users/carl/db/postgresql start

eg
>pg_ctl -D /database_directory -l /log_file.log start

Error Message:
FATAL:  could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied

Solution:
>sudo rm -fr /tmp/.s.PGSQL.5432.lock

Error Message:
LOG:  could not bind Unix socket: Address already in use HINT:  Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry. WARNING:  could not create Unix-domain socket in directory "/tmp" FATAL:  could not create any Unix-domain sockets

Solution:
>sudo rm -fr /tmp/.s.PGSQL.5432

Solved
LOG:  database system was shut down at 2014-03-21 16:59:46 CDT LOG:  autovacuum launcher started LOG:  database system is ready to accept connections

List the databases we have
>psql -l

3. Create the Right DB with Auth
List all the users on MAC System
>ls /Users

Create a user named postgres
>su postgres
>psql

Error Message:
FATAL:  role "postgres" does not exist psql: FATAL:  role "postgres" does not exist

Solution:
>createuser postgres
>createdb -Opostgres -Eutf-8 demo

Logon to the DB with the right user
>psql -U postgres demo

or 

>psql -U postgres -d demo -h localhost -p 5432

4. Some Basic Commands
List all the Databases
demo=> \l                                List of databases   Name    |  Owner   | Encoding |   Collate   |    Ctype    | Access privileges -----------+----------+----------+-------------+-------------+------------------- demo      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 

Connect to other databases
demo=> \c demo You are now connected to database "demo" as user "postgres". demo=> demo=> \c postgres You are now connected to database "postgres" as user "postgres".

SQL Command
create table, insert data and etc
>create table usertable(name VARCHAR(20), signupdate DATE);
>insert into usertable (name, signupdate ) values ('sillycat', '2014-03-24' );
>select * from usertable;

List all the tables We have
demo=> \d           List of relations Schema |   Name    | Type  |  Owner   --------+-----------+-------+---------- public | usertable | table | postgres

List the description of one Table, e.g. usertable
demo=> \d usertable            Table "public.usertable"   Column   |         Type          | Modifiers ------------+-----------------------+----------- name       | character varying(20) |  signupdate | date                  | 

List all the Users
demo=> \du                             List of roles Role name |                   Attributes                   | Member of -----------+------------------------------------------------+----------- carl      | Superuser, Create role, Create DB, Replication | {} postgres  |                                                | {}

List the Connection Info
demo=> \conninfo You are connected to database "demo" as user "postgres" on host "localhost" at port "5432".


References:
http://www.postgresql.org/
https://github.com/mauricio/postgresql-async

http://book.51cto.com/art/201201/313178.htm
http://www.ruanyifeng.com/blog/2013/12/getting_started_with_postgresql.html
http://mac-dev-env.patrickbougie.com/postgresql/
http://ionrails.com/2012/06/03/installing-postgresql-on-a-mac-lion/


分享到:
评论

相关推荐

    dbeaver-ce-7.2.3-x86_64-setup.exe

    DBeaver是一个SQL客户端和数据库管理工具。对于关系数据库,它使用JDBC API...支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HS DBeaver的社区版是一个自由及开放源代码软件,在Apache License下分发。

    db-setup-action:GitHub Action自动执行本地RDBMS设置(基于Docker)

    数据库设置操作 db-setup-action自动执行本地数据库(基于Docker)的安装和运行。 目前支持: PostgreSQLSQL服务器该安装使用官方Docker映像,请参阅下面每个数据库中的链接。 此操作的主要目的是为测试自动化提供一...

    DBeaver (dbeaver-ce-21.2.5-x86_64-setup.exe)

    DBeaver (dbeaver-ce-21.2.5-x86_64-setup.exe)适用于Windows 64 位(安装程序)。DBeaver 是一个通用的数据库管理工具和 SQL 客户端,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HSQLDB, Derby...

    dbeaver-ce-7.3.2-x86_64-setup.exe

    其支持:MySQL、Oracle、PostgreSQL、IBM DB2、Microsoft SQL Server、clickhouse、Sybase、ODBC、Java DB (Derby)、Firebird (Interbase)、HSQLDB、SQLite、Mimer、H2、IBM Informix、SAP MAX DB、Cache、Ingres、...

    munin_postgresql_table_stats:基于每个表的 postgresql munin 脚本

    如果您链接 postgres_setup_db_[database] 它将为数据库中的每个普通表设置选择和插入 munin 图,但是 /etc/munin/plugins 目录必须可由您的 munin 进程写入。 需要 /etc/munin/plugin-conf.d/[any filename] 中的...

    dbeaver-ce-5.2.1-x86_64-setup (installer + JRE)

    DBeaver 是一个通用的数据库管理工具和 SQL 客户端,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HSQLDB, Derby, 以及其他兼容 JDBC 的数...

    openbrewerydb-rails-api:使用Ruby on Rails构建的官方v1 Open Brewery DB REST API

    :clinking_beer_mugs: ... 运行bundle exec rails db:setup 运行bundle exec rails s 该服务器将在http://localhost:3000 数据库期望 对于本地PostgreSQL服务配置,有一些假设。 主机是localhost或127.0.0.1 用户

    dbeaver-ee-4.1.0-x86_64-setup

    DBeaver [1] 是一个通用的数据库管理工具和 SQL 客户端,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HSQLDB, Derby, 以及其他兼容 JDBC 的数据库。DBeaver 提供一个图形界面用来查看数据库结构、...

    DBeaver (dbeaver-ce-21.3.2-x86_64-setup.exe)

    DBeaver (dbeaver-ce-21.3.2-x86_64-setup.exe)适用于Windows 64 位(安装程序)。DBeaver 是一个通用的数据库管理工具和 SQL 客户端,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HSQLDB, Derby...

    dbeaver-ce-latest-x86_64-setup 2022.04

    DBeaver 是一个通用的数据库管理工具和 SQL 客户端,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HSQLDB, Derby, 以及其他兼容 JDBC 的数据库。DBeaver 提供一个图形界面用来查看数据库结构、执行...

    通用数据库工具 支持几乎所有数据库 开源 dbeaver-ce-7.0.0-x86_64-setup

    DBeaver 通过 JDBC 连接到数据库,可以支持几乎所有的数据库产品,包括:MySQL、PostgreSQL、MariaDB、SQLite、Oracle、Db2、SQL Server、Sybase、MS Access、Teradata、Firebird、Derby 等等。商业版本更是可以支持...

    nba-shots-db:用NBA射门数据填充数据库

    NBA Shots DB Rails应用程序用于填充PostgreSQL数据库,其中包含自1996年以来NBA的所有尝试射门。 博客文章,对数据进行...bundle exec rake db:setup 用法 导入所有可用数据(将需要几个小时): bundle exec rake

    蝙蝠:F#SAFE应用程序+ EF Core(PostgreSQL和SQLite)

    在bat_db_1和bat_server_1容器均已构建并运行之后,打开另一个终端并使用以下命令在服务器容器中运行测试: docker exec bat_server_1 sh -c " ./run-tests.sh " 享受。 开发说明 接下来,您将获得有关开发工具...

    dbeaver-ce-6.3.5-64-setup.rar

    dbeaver支持很多的数据库,比如常见的MySQL、Oracle、PostgreSQL、IBM DB2等等,

    dbeaver-ce-6.2.4-x86_64-setup.exe

    DBeaver 通过 JDBC 连接到数据库,可以支持几乎所有的数据库产品,包括:MySQL、PostgreSQL、MariaDB、SQLite、Oracle、Db2、SQL Server、Sybase、MS Access、Teradata、Firebird、Derby 等等。商业版本更是可以支持...

    dbeaver-ce-7.2.0-x86_64-setup.exe

    DBeaver 是一个通用的数据库管理工具和 SQL 客户端,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HS

    dbeaver-ce-7.0.5-x86_64-setup.exe

    dbeaver通用数据库工具,支持 MySQL, PostgreSQL, Oracle, DB2, MSSQL, Sybase, Mimer, HSQLDB, Derby

    dbeaver-ce-7.3.4-x86_64-setup.exe

    适用于开发人员,SQL程序员,数据库管理员和分析人员的免费多平台数据库工具。...使用插件架构,并为以下数据库提供附加功能:MySQL / MariaDB,PostgreSQL,Greenplum,Oracle,DB2 LUW,Exasol等等。

    dbeaver-ce-21.1.1-x86-64-setup

    DBeaver 通过 JDBC 连接到数据库,可以支持几乎所有的数据库产品,包括:MySQL、PostgreSQL、MariaDB、SQLite、Oracle、Db2、SQL Server、Sybase、MS Access、Teradata、Firebird、Derby 等等。商业版本更是可以支持...

    pgbase:使用PostgreSQL基本软件包

    python3 setup.py install 要验证安装,请尝试: import pgbase 用法示例 from pgbase . database . db import DB # - создаем объект класса DB db = DB ( user = '<username>' ) # - вып...

Global site tag (gtag.js) - Google Analytics