postgresql 创建数据库问题

postgresql 创建数据库问题,第1张

1、使用CREATE DATABASE

命令将创建一个数据库PostgreSQL的shell提示符,但你应该有适当的权限来创建数据库。默认情况下,创建新的数据库将通过克隆标准系统数据库template1。

语法:

CREATE DATABASE语句的基本语法如下:

CREATE DATABASE dbname;

其中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-#

如何使用直连方式连接数据库

1,ArcGIS101统一了数据库连接,也就是不区分是空间数据库连接还是通过OLEDB方式的关系型数据库连接

2,在Catalog中只能采用直连方式;

3,ArcGIS101版本中,Esri提供的安装介质不在包含Postgresql(以前的是包含的);

4,安装Postgresql,官方给的软件要求是64位数,而且所有的企业级数据库都是64位(这应该和Server有关系吧,因为Server101是纯64位,在桌面软件的目录中给出的几个dll都是64位,这几个dll后面会用到,官方给的软件需求如下:

Database

SupportedOperatingSystems

MinimumOSVersion

MaximumOSVersion

PostgreSQL905(64-bit)

RedHatEnterpriseLinuxServer5(64-bit)

Update7

RedHatEnterpriseLinuxServer6(64-bit)

SUSELinuxEnterpriseServer11(64-bit)

SP1

WindowsServer2003Standard,Enterprise,andDatacenter(64-bit[EM64T])

SP2

SP2

WindowsServer2008R2Standard,Enterprise,andDatacenter(64-bit[EM64T])

SP1

5,配置PostgreSQL的客户端。因为直连方式要求ArcSDE的客户端必须安装数据库的客户端类库,所以首先需要获取PostgreSQL的客户端。ArcGISDesktop是32位软件,需要的是32位的PostgreSQL类库。找到PostgreSQL的客户端,或者在别的机器上将32位的libeay32dll,libiconv-2dll,libintl-8dll,libpqdll,andssleay32dll文件拷贝到Desktop安装目录的bin目录下;

6,拷贝st_geometrydll,将Desktop安装目录下的/PostgreSQL/Windows64(看到64了吧)目录下,拷贝st_geometrydll文件到PostgreSQL的lib目录。在PostgreSQL中创建Geodatabase时必须用到此类库;

7,配置pg_hbaconf,修改PostgreSQ的pg_hbaconf文件,添加“hostallall0000/0md5”(关于该文件的配置,可以参阅相关资料);

8,在安装完SDE后,发现没有以往的post界面,在101中,对于创建企业级Geodatabase都采用工具箱中提供的工具,换句话说,以前的post被Toolbox中的一堆工具替代;

9,创建地理数据库

101在创建地理数据库的时候,提供了三个,Oracle,SQLServer和Postgresql,我们用这个工具创建地理数据库,这个过程相当于早起的POST过程,创建数据库并写入一堆系统表等

创建一张志愿者的数据表,记录每批参加志愿活动的人员名单。其中人员信息保存在json字段中。

知识点 : (1)postgresql中自增长的id创建。 (2)修改表字段语句。 (3)标准sql中table name ,column name双引号。

查询年龄大于等于25岁以上的志愿者

知识点 : (1)查询结果的的row number生成。 (2)获取json对象中的子对象。 (3)转换json对象属性的数据类型。

首先知道substring函数在PostgreSQL中的作用。在这段SQ语句中,substring是使用的substring(txt from reg)的形式,其中, txt是要进行正则匹配的源字符串,reg是匹配的正则表达式。如此,我们大概可以知道:这段代码的then其实就是用information进行一些正则表达式的匹配,然后获取匹配后的那段字符串。

这段代码中一共有3个substring函数调用,而执行的顺序则与它们出现的顺序相反,首先执行的是:

substring(information from E':step_1: \\([0 -9]+)' )

它获得匹配step_1: 后面所跟的数字;假设information为:step_1: 1234a, 那么获得的就是1234;

接下来为第二substring, 它是用information来匹配上面获得的数字嵌入":&"和":step_1:"的那段内容;

而最后一个substring,则是匹配第二个获得的字串,其中前为“loan_purpose: ”接下来为非换行符号的那部分字串(即获得以“loan_purpose: ”开始的所有非换行字符,遇到换行符就终止,不包括"loan_purpose: ")。

一个例子:

select substring( substring( information FROM': &' ||  substring(information from E':step_1: 

\\([0-9]+)'

) ||':step_1:') 

from E'loan_purpose: ([^\n]+)')

from (select 'start here: &1234loan_purpose: Hello World:step_1: 1234end'::character varying as information)

s

运行结果如图,

以上就是关于postgresql 创建数据库问题全部的内容,包括:postgresql 创建数据库问题、arcgis数据库用的什么数据库系统(arcgis数据库建库)、PostGreSQL Json数据存储和条件查询等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9690546.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存