简体   繁体   English

在远程机器上创建 PostgreSQL 数据库

[英]PostgreSQL Database Creation on Remote machine

我们可以在 postgresql DB 中的远程机器上创建一个数据库,如果是,那么如何?

Yes.是的。 Assuming the remote server is Linux, and assuming you have sudo or root privileges on that server, you could SSH into the remote server and use a package manager (like yum, synaptic, or apt) to install the PostgreSQL server.假设远程服务器是 Linux,并且假设您在该服务器上具有 sudo 或 root 权限,您可以通过 SSH 连接到远程服务器并使用包管理器(如 yum、synaptic 或 apt)来安装 PostgreSQL 服务器。

You can configure it using vi (or emacs or other text editor).您可以使用 vi(或 emacs 或其他文本编辑器)对其进行配置。 Usually, the files you edit are found in the /var/lib/pgsql/data folder, and an /etc/init.d/postgresql startup script for whenever the server reboots.通常,您编辑的文件位于 /var/lib/pgsql/data 文件夹中,以及每当服务器重新启动时使用的 /etc/init.d/postgresql 启动脚本。 You'll usually need to edit the pg_hba.conf file to allow a connection from your client's subnet.您通常需要编辑 pg_hba.conf 文件以允许来自客户端子网的连接。 That part can be troublesome if overlooked.如果被忽视,那部分可能会很麻烦。

You'll be able to initially run psql as the postgres user, and can create datatabases, run scripts, etc from the command line.您将能够最初以 postgres 用户身份运行 psql,并且可以从命令行创建数据库、运行脚本等。 Once you allow a remote connection, you can do the same from the comfort of your own gui, such as PgAdminIII or any Java-based database manager that can use a JDBC connector.一旦您允许远程连接,您就可以在您自己的 gui 中进行相同的操作,例如 PgAdminIII 或任何可以使用 JDBC 连接器的基于 Java 的数据库管理器。

Example:例子:

psql -U postgres
create database foo;
\q

First, get your programming language.首先,获取您的编程语言。 Let say it's PHP to make it simple.假设它是 PHP 以使其变得简单。

Second, you get the PostGresql connector .其次,您将获得 PostGresql连接器 Here is the link for PHP but you can get for all popular language.这是 PHP 的链接,但您可以获得所有流行语言的链接。

Third, you open a connection and you do the command you want.第三,您打开一个连接并执行您想要的命令。 You want to create a database so you call the create database YourDatabaseName command.您想要创建一个数据库,因此您调用create database YourDatabaseName命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM