postgresql初始数据库
1、使用CREATE DATABASE 该命令将创建一个数据库PostgreSQL的shell提示符,但你应该有适当的权限来创建数据库。默认情况下,创建新的数据库将通过克隆标准系统数据库template1。 语法: CREATE DATABASE语句的基本语法如下: CREATE DATABASE db...
② postgresql是什么数据库
postgresql是功能强大的开源数据库。
postgresql数据库是功能强大的开源数据库,它支持丰富的数据类型(如JSON和JSONB类型、数组类型)和自定义类型。
PostgreSQL数据库提供了丰富的接口,可以很方便地扩展它的功能,如可以在GiST框架下实现自己的索引类型,支持使用C语言写自定义函数、触发器,也支持使用流行的编程语言写自定义函数。
PostgreSQL数据库优点
1、对超许可数量软件使用的天然免疫力
对一些商业性质的数据库销售商来说,超许可数量的软件使用是第一位的问题。而使用PostgreSQL,因为没有任何授权的费用是,也就没有任何人可以起诉您违反授权协议违规使用软件。
2、比商业服务商更好的支持
除了有一般商业公司的支持外,我们还有由PostgreSQL专业人员和热心的爱好者组成的各种社区,用户可以向他们寻求支持和帮助。
3、员工成本的显着降低
相对于市场上大型的商业私有数据库软件,我们的系统在设计和开发时已考虑仅需少量的维护和优化,同时仍保持所有功能正常、稳定和性能正常。不仅如此,我们的培训过程相对于那些商业私有数据库供应商来说,总体来说有更好的性价比、更容易管理和更接近真实的使用场景。
4、享有盛名的可靠性和稳定性
与很多商业私有数据库不一样的是,对很多公司特别常见的是,PostgreSQL在几年的运行过程中几乎未出现哪怕是一次的宕机情况,即使是一次,它就是这样稳定地工作着。
5、扩展性
所有PostgreSQL的源代码对所有人都是可以免费获得的。如果您的公司员工需要定制或是给PostgreSQL增加一些功能,他们只需做很少的改动工作,也没有额外的成本。全球PostgreSQL社区的专业人员和热心的爱好者也在积极地扩展PostgreSQL的功能。
③ 如何访问GitLab默认安装的PostgreSQL数据库
将GitLab的数据库导入阿里云PostgreSQL RDS
GitLab的数据库用的是PostgreSQL,之前由于阿里云RDS不支持PostgreSQL,只能将GitLab的数据库部署在云服务器上。
6月1日得知阿里云推出了PostgreSQL RDS,于是立马将GitLab的数据库迁移至PostgreSQL RDS。
下面分享一下迁移的主要操作步骤:
1)在GitLab服务器上备份GitLab数据库
操作命令:
sudo gitlab-rake gitlab:backup:create SKIP=db
注:这个命令原本是只备份数据库,但实际运行时也会备份repositories,可以在完成数据库备份时,ctrl+C直接退出。
数据库备份成功后,会在 /var/opt/gitlab/backups/db 文件夹中看到 database.sql 文件,导入时只需将这个文件导入到阿里云RDS。
2)在阿里云RDS中创建GitLab的数据库帐户与数据库
在阿里云RDS控制台首页点击逗登录数据库地,进入idb.rds.aliyun.com,选择对应的PostgreSQL实例。
a)创建2个帐户:gitlab, gitlab-psql
b)创建gitlabhq_proction数据库,所有者为gitlab。
3) 在GitLab服务器上进行导入操作
a) cd /var/opt/gitlab/backups/db
b) psql -h [RDS实例网址] p 3433 -d gitlabhq_proction -U gitlab -f database.sql
④ 怎么创建postgresql数据库
1.在数据库服务器安装完成后,默认有三个数据库,可以通过下面两种方法查看。
[html] view plain print?
postgres=# SELECT * FROM pg_database;
datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | dattablespace | datc
onfig | datacl
-----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+---------------+-----
------+-------------------------------------
template1 | 10 | 6 | zh_CN.UTF-8 | zh_CN.UTF-8 | t | t | -1 | 11563 | 648 | 1663 |
| {=c/postgres,postgres=CTc/postgres}
template0 | 10 | 6 | zh_CN.UTF-8 | zh_CN.UT
⑤ 如何在windows下手动初始化PostgreSQL数据库
PostgreSQL数据库手动初始化步骤:
1、创建用户postgres,密码同样是postgres:
net user postgres postgres /add
2、在数据库根目录下建立data目录:
C:\Program Files\PostgreSQL\9.3>md data
3、去掉administrator对data目录的权限:
C:\Program Files\拦拦PostgreSQL\前衡皮9.3>cacls data /e /t /r administrator
处理的目录: C:\Program Files\PostgreSQL\9.3\data
4、将data目录的权限赋给postgres用户:
C:\Program Files\PostgreSQL\9.3>cacls data /e /t /g postgres:C
处理的目录: C:\Program Files\PostgreSQL\9.3\data
5、用postgres用户打开cmd
C:\Program Files\PostgreSQL\9.3>runas /user:postgres cmd.exe
输入 postgres 的密码慧差:
试图将 cmd.exe 作为用户 "SURE-PC\postgres" 启动...
6、进行初始化,初始化用户为postgres,字符集为utf8,locale为C:
C:\Program Files\PostgreSQL\9.3\bin>initdb.exe -D ../data -E utf8 --locale C -U
postgres
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory ../data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in ../data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... not supported on this platform
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
ing template1 to template0 ... ok
ing template1 to postgres ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
"postgres" -D "../data"
or
"pg_ctl" -D "../data" -l logfile start
C:\Program Files\PostgreSQL\9.3\bin>
7、启动数据库,进入客户端:
C:\Program Files\PostgreSQL\9.3\bin>"pg_ctl" -D "../data" start
server starting
C:\Program Files\PostgreSQL\9.3\bin>LOG: database system was shut down at 2014-
09-18 10:19:54 HKT
LOG: autovacuum launcher started
C:\Program Files\PostgreSQL\9.3\bin>LOG: database system is ready to accept con
nections
C:\Program Files\PostgreSQL\9.3\bin>psql.exe
psql (9.3.5)
Type "help" for help.
postgres=#
8、初始化完成。
⑥ postgresql 创建数据库问题
1、使用CREATE DATABASE
该命令将创建一个数据库PostgreSQL的shell提示符,但你应该有适当的权限来创建数据库。默认情况下,创建新的数据库将通过克隆标准系统数据库template1。
语法:
CREATE DATABASE语句的基本语法如下:
CREATEDATABASEdbname;
其中dbname是要创建的数据库的名称。
例子:
下面是一个简单的例子,这将创建testdb在PostgreSQL模式:
postgres=# CREATE DATABASE testdb;
postgres-#
2、使用createdb的命令
PostgreSQL命令行可执行createdb是是SQL命令CREATE DATABASE一个包装器。此命令和SQL命令CREATE DATABASE之间唯一的区别是,前者可以直接在命令行中运行,它允许的注释被添加到数据库中,全部在一个命令。
语法:
createdb语法如下所示:
createdb [option...] [dbname [description]]
参数
下表列出了参数及它们的描述。
参数名称 描述
dbname The name of a database to create.
description Specifies a comment to be associated with the newly created database.
options command-line arguments which createdb accepts.
选项
下表列出了命令行参数CREATEDB接收:
选项 描述
-D tablespace Specifies the default tablespace for the database.
-e Echo the commands that createdb generates and sends to the server.
-E encoding Specifies the character encoding scheme to be used in this database.
-l locale Specifies the locale to be used in this database.
-T template Specifies the template database from which to build this database.
--help Show help about dropdb command line arguments, and exit.
-h host Specifies the host name of the machine on which the server is running.
-p port Specifies the TCP port or the local Unix domain socket file extension on which the server is listening for connections.
-U username User name to connect as.
-w Never issue a password prompt.
-W Force createdb to prompt for a password before connecting to a database.
打开命令提示符,然后去是PostgreSQL安装所在的目录。进入到bin目录,执行下面的命令创建一个数据库。
createdb -h localhost -p 5432 -U postgress testdb
password ******
上面的命令会提示Postgres的默认的PostgreSQL管理用户的密码,以便提供密码和继续创建新的数据库。
一旦创建数据库时可以使用上述方法,可以检查它在列表中的数据库使用l即反斜线el命令如下:
postgres-# l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
testdb | postgres | UTF8 | C | C |
(4 rows)
postgres-#