博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Postgres study reminder ,lesson 1
阅读量:6991 次
发布时间:2019-06-27

本文共 2680 字,大约阅读时间需要 8 分钟。

hot3.png

Just want to learn the postgres database in details from now on, try to write this blog to push myself working on it.

This is the first lesson of my series for postgres,

Subject is very simple, prepare the postgres ENV , and try to create a new database and user.

I am going to use the docker for the ENV. Just try to use a new way, and try to make docker study useful here.

If you don't like it, or prefer the more tradional solution, Just check the official postgres installation tutorial.

If you like docker,but don't know how to start it, please try search for docker's offical doc. I just a freshman here. And I just want to keep focus on postgres here too.

Key codes for pg related issus are listed below:


#start my postgres db

docker run --name pgstudy -e POSTGRES_PASSWORD=1q -d postgres

#connect with the pgsql

docker run -it --link pgstudy:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'


As the comments say,I just first create a new postgres container for server, named pgstudy,

then ,I use a oneshot psql client to working on it.

The result of the second command is listed below. 

[postgresqlCookbook]$ docker run -it --link pgstudy:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'

Password for user postgres:

psql (9.4.4)

Type "help" for help.

postgres=#

As you can see, I can do the psql command now. HaHa.

Now, let's just first create the user , e.g. hr, password is hr too.

CREATE USER hr with PASSWORD 'hr';

Now to create the db.(just copy the book material here):

PostgreSQL provides two methods to create a new database:

  • The first method relies on using the CREATE DATABASE SQL statement:

    CREATE DATABASE hrdb WITH ENCODING='UTF8' OWNER=hr CONNECTION LIMIT=25;
  • The second method requires using the createdb command-line executable:

    createdb –h localhost –p 5432 –U postgres testdb1

Now we can check for the database for confirmation:Just type "\l" in the pg command line:


postgres=# \l

                                 List of databases

   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges

-----------+----------+----------+------------+------------+-----------------------

 hrdb      | hr       | UTF8     | en_US.utf8 | en_US.utf8 |

 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |

 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +

           |          |          |            |            | postgres=CTc/postgres

 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +

           |          |          |            |            | postgres=CTc/postgres

(4 rows)

postgres=#


OK . This is the beginning of my pg study  series. Hope it can carry on with a complete ending.

转载于:https://my.oschina.net/hunterXue/blog/508286

你可能感兴趣的文章
fastjson 总结
查看>>
介绍遍历子表的方法
查看>>
网络的分类
查看>>
PGSQL创建自增的id-- postgresql nextval 使用
查看>>
12python程序另一种运行方式
查看>>
Tomcat高级应用(添加虚拟主机及优化)
查看>>
Kindeditor(jsp)与SSH三大框架整合上传图片出错问题解决方案
查看>>
eyoucms网站基本信息设置
查看>>
如何优雅地实现分页查询
查看>>
常用安装rpm包--必备命令
查看>>
表单验证 018
查看>>
Java字节码3-使用ByteBuddy实现一个Java-Agent
查看>>
程序有没有可能输出y=2而x!=1的情况?如果可能,x可能会是什么值?如果不可能,为什么?...
查看>>
[笔记] mysql-proxy 实现主从读写分离
查看>>
Mina自定义文本解码
查看>>
apache+mysql+php环境部署详解
查看>>
vim的使用
查看>>
Web开发者必备的10个PHP代码片段
查看>>
5、Python —— 模块
查看>>
2.zephir基础语法
查看>>