Mac上使用homebrew安装PostgreSql

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:

安装

brew 安装 postgresql :

$ brew install postgresql

查看安装的版本:

$ pg_ctl -V
pg_ctl (PostgreSQL) 9.3.5

安装成功之后,安装路径为:/usr/local/var/postgres

接下来,初始化数据库:

$ initdb /usr/local/var/postgres
The files belonging to this database system will be owned by user "june".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /usr/local/var/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
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
copying template1 to template0 ... ok
copying 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 /usr/local/var/postgres
or
    pg_ctl -D /usr/local/var/postgres -l logfile start

配置开机登陆(可选):

$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/postgresql/9.3.5_1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

手动启动 postgresql

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

查看状态:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log status

停止:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log stop -s -m fast

查看进程:

$ ps auxwww | grep postgres
june            56126   0.0  0.0  2432772    644 s000  S+    5:01下午   0:00.00 grep postgres
june            56058   0.0  0.0  2467360    584   ??  Ss    5:00下午   0:00.00 postgres: stats collector process
june            56057   0.0  0.0  2611808   1744   ??  Ss    5:00下午   0:00.00 postgres: autovacuum launcher process
june            56056   0.0  0.0  2611676    696   ??  Ss    5:00下午   0:00.00 postgres: wal writer process
june            56055   0.0  0.0  2611676    944   ??  Ss    5:00下午   0:00.01 postgres: writer process
june            56054   0.0  0.0  2611676    756   ??  Ss    5:00下午   0:00.00 postgres: checkpointer process
june            56044   0.0  0.2  2611676  14096 s000  S     5:00下午   0:00.02 /usr/local/Cellar/postgresql/9.3.5_1/bin/postgres -D /usr/local/var/postgres

创建用户和数据库:

#createuser will prompt you for a password, enter it twice.
$ createuser  -P test
$ createdb -Otest -Eutf8 test_db
$ psql
postgres=# GRANT ALL PRIVILEGES ON test TO test;
postgres=# \q

进入命令行模式:

$ psql -U test test_db -h localhost -W

如果出现 FATAL: Ident authentication failed for user,是因为:

This is because by default PostgreSQL uses ‘ident’ authentication i.e it checks if the username exists on the system. You need to change authentication mode to ‘trust’ as we do not want to add a system user. Modify the settings in “pg_hba.conf” to use ‘trust’ authentication.

请修改 /usr/local/var/postgres/pg_hba.conf 为:

host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

安装 pgadmin,下载地址:http://www.pgadmin.org/download/macosx.php

卸载

$ brew uninstall postgres

如果配置了开机登陆:

$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ rm -rf ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
19天前
|
存储 关系型数据库 MySQL
mysql安装教程mac
【4月更文挑战第21天】
|
20小时前
|
NoSQL Redis Docker
Mac上轻松几步搞定Docker与Redis安装:从下载安装到容器运行实测全程指南
Mac上轻松几步搞定Docker与Redis安装:从下载安装到容器运行实测全程指南
8 0
|
1天前
mac10.9安装win7
mac10.9安装win7
|
1天前
|
安全 Java iOS开发
MAC OS X 硬盘安装详细分解教程
MAC OS X 硬盘安装详细分解教程
10 1
|
1天前
|
IDE 5G 开发工具
HP4230s笔记本安装mac os总结(原创)
HP4230s笔记本安装mac os总结(原创)
|
1天前
|
编解码 Oracle iOS开发
VirtualBox虚拟机安装Mac OS X Lion系统详解
VirtualBox虚拟机安装Mac OS X Lion系统详解
|
2天前
|
关系型数据库 MySQL 分布式数据库
快速体验开源PolarDB -X 部署安装
在CentOS上部署PolarDB-X标准版集群的体验包括三步:安装python3和docker(如果未预装),然后使用venv创建环境,安装pxd并验证。接着,通过`pxd tryout -t standard`部署集群,该过程需拉取大量镜像,可能耗时且占用数GB空间,建议事先清理空间并了解资源需求。部署后,可查询集群状态和健康信息。最终,使用`pxd cleanup`清理。过程中因磁盘空间不足遇到问题,建议体验前提供系统配置需求,并允许用户自定义MySQL参数。
|
3天前
|
关系型数据库 Linux 分布式数据库
源码编译实现PolarDB-X部署安装的体验报告
本文档记录了编译安装PolarDB-X的步骤,包括设置CentOS开发环境、从GitHub获取源码、编译(耗时较长)、解决依赖和权限问题、安装部署及测试验证。作者建议优化文档细节、减少编译时间、改进错误提示,并提议提供一键安装依赖脚本、新手视频教程及加强社区支持。整个过程虽有挑战,但具有成就感。
15 0
|
3天前
|
Ubuntu 关系型数据库 MySQL
使用PXD工具一键安装PolarDB-X的体验
这次体验挺有意思的,对PolarDB-X有了更深入的了解,也希望能通过这些建议帮助产品做得更好。
13 1
使用PXD工具一键安装PolarDB-X的体验
|
10天前
|
SQL 关系型数据库 数据库
如何在 Debian 12 上安装 PostgreSQL?
【4月更文挑战第25天】
24 0