美文网首页环境搭建
postgresql - mac - brew -安装与启动

postgresql - mac - brew -安装与启动

作者: IntoTheVoid | 来源:发表于2020-03-18 15:55 被阅读0次

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update

Installing

  1. In your command-line run the command: brew install postgresql

  2. Run the command: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

  3. Create two new aliases to start and stop your postgres server. They could look something like this:

    alias pg_start="launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"
    alias pg_stop="launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist"
    
    
  4. Run the alias you just created: pg_start. Use this comment to start your database service.

    • alternatively, pg_stop stops your database service.
  5. Run the command: createdbwhoami``

  6. Connect to your postgres with the command: psql

  7. brew reinstall readline - if needed

  8. createuser -s postgres - fixes role "postgres" does not exist

  9. Test with psql command

    $ psql
    psql (10.0)
    Type "help" for help.
    
    ibraheem=# 
    
    

Details

What is this ln command I ran in my Terminal?

from the man ln command

The ln utility creates a new directory entry (linked file) which has the same modes as the original file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the copies''; instead, a linkpoints'' to the original copy. There are two types of links; hard links and symbolic links. How a link ``points'' to a file is one of the differences between a hard and symbolic link.

What is launchctl?

from the man launchctl command

launchctl interfaces with launchd to manage and inspect daemons, angents and XPC services.

Commands

Create database

createdb <database_name>

createdb mydjangoproject_development

List databases

psql -U postgres -l

Show tables in database

psql -U postgres -d <database_name>

psql -U postgres -d mydjangoproject_development

Drop database

dropdb <database_name>

dropdb mydjangoproject_development

Restart database

dropdb <database_name> && createdb <database_name>

dropdb mydjangoproject_development && createdb mydjangoproject_development

转载自:https://gist.github.com/ibraheem4/ce5ccd3e4d7a65589ce84f2a3b7c23a3

连接AWS上的postgresql 排除连接问题

如果无法连接到数据库实例,则最常见的错误是 Could not connect to server: Connection timed out.如果出现此错误,请执行以下操作:

  • 检查所使用的主机名是否是数据库实例终端节点,以及所使用的端口号是否正确。

  • 确保数据库实例的公开可访问性设置为 Yes (是)

  • 检查分配给数据库实例的安全组是否具有允许您的连接通过相应防火墙进行访问的规则。例如,如果数据库实例是使用默认端口 5432 创建的,您公司的防火墙规则可能不允许公司设备连接到该端口。

    要修复此故障,请修改数据库实例以使用不同的端口。另外,确保应用于数据库实例的安全组允许连接到新端口。

  • 检查数据库实例是否是使用安全组创建的,而该安全组没有授权来自运行应用程序的设备或 Amazon EC2 实例的连接。要使连接运行,您在创建数据库实例时分配给它的安全组必须允许访问该数据库实例。例如,如果数据库实例是在 VPC 中创建的,则它必须具有授权连接的 VPC 安全组。

    您可以在安全组中添加或编辑入站规则。对于 Source,选择 My IP。这允许从浏览器中检测到的 IP 地址访问数据库实例。有关更多信息,请参阅Amazon Virtual Private Cloud VPC 和 Amazon RDS

    或者,如果数据库实例是在 VPC 外部创建的,则它必须具有授权这些连接的数据库安全组。

到目前为止,最常见的连接问题与分配给数据库实例的安全组的访问规则有关。如果在创建数据库实例时使用的是默认数据库安全组,则该安全组可能没有允许您访问该实例的访问规则。有关 Amazon RDS 安全组的更多信息,请参阅 使用安全组控制访问权限

如果在连接时收到 FATAL: databasesome-namedoes not exist 之类的错误,请尝试对 --dbname 选项使用默认数据库名称 postgres

相关文章

网友评论

    本文标题:postgresql - mac - brew -安装与启动

    本文链接:https://www.haomeiwen.com/subject/moqcyhtx.html