【问题标题】:Installing PostgreSQL and `createdb` with Terminal使用终端安装 PostgreSQL 和`createdb`
【发布时间】:2019-05-06 02:45:54
【问题描述】:

terminalHomebrew 安装PostgreSQL 后...

➜ ~ brew link postgresql

Warning: Already linked: /usr/local/Cellar/postgresql/11.2_1: 3,186 files, 35.3MB

To relink: brew unlink postgresql && brew link postgresql

➜ ~ brew services 重启 postgresql

Successfully stopped postgresql (label: homebrew.mxcl.postgresql)

Successfully started postgresql (label: homebrew.mxcl.postgresql)

➜ ~ createdb 'test'

createdb: could not connect to database template1: could not connect to server: No server file or directory

Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

我希望能够严格从终端运行,并且不受使用 PSequel GUI...

谢谢,

【问题讨论】:

    标签: postgresql terminal homebrew


    【解决方案1】:

    已解决

    我的主要问题是:

    ➜ ~ createdb 'test'

    createdb: could not connect to database template1: could not connect to server: No server file or directory  
    Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
    

    这个问题简单地解决了:

    ➜ ~ postgres -D /usr/local/var/postgres

    调用了数据库目录...

    2019-05-06 14:20:37.367 EDT [41854] LOG:  listening on IPv6 address "::1", port 5432  
    2019-05-06 14:20:37.367 EDT [41854] LOG:  listening on IPv4 address "127.0.0.1", port 5432  
    2019-05-06 14:20:37.367 EDT [41854] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"  
    2019-05-06 14:20:37.384 EDT [41854] LOG:  database system is ready to accept connections
    

    保持运行,并在我的终端上打开一个新标签:

    ➜ ~ createdb 'test'

    ➜ ~ psql '测试'

    psql (11.2)
    
    Type "help" for help.
    
    test=#
    

    在我的调试过程中使用的其他东西:

    删除旧的数据库文件(这很危险)

    ➜ ~ rm -rf /usr/local/var/postgres

    跟进

    ➜ ~ initdb /usr/local/var/postgres

    initdb 不用于创建“新数据库”

    As Documented in the Manual你需要它来创建一个“集群”或“数据目录”,然后存储使用createdb创建的数据库

    引自手册:

    在您可以做任何事情之前,您必须在磁盘上初始化一个数据库存储区域。我们称之为数据库集群。 (SQL 标准使用术语目录集群。)数据库集群是由正在运行的数据库服务器的单个实例管理的数据库集合

    [...]

    在文件系统方面,数据库集群是一个目录,所有数据都将存储在该目录下。我们称之为数据目录或数据区

    简而言之:initdb 在硬盘上创建必要的目录布局,以便能够创建和管理数据库。

    它是 Postgres 服务器安装过程的必要部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 2023-01-08
      • 1970-01-01
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      相关资源
      最近更新 更多