当前位置:   article > 正文

mac M1 安装 PostgreSQL_m1安装postpresql

m1安装postpresql

安装方式

1、dmg 安装包安装

参考链接:https://www.cnblogs.com/Simple-Small/p/12882594.html

按照大佬的安装过程安装既可,中途会遇到以下报错

Problem running post-install step. Installation may not complete correctly The database cluster initialisation failed.

我根据大佬的解决方案未解决该报错,并尝试了诸多方法,降低版本等都不可行;

stack overflow 相关问题的解决方案,我选择放弃dmg方式的傻瓜安装,采用 brew 的安装方式

2、brew 安装

首先要在mac上安装最新的 Homebrew

如果没有安装可以在 terminal 键入以下命令安装,安装失败大概率是连不上服务器,可以采用国内镜像

/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)
   
   
    • 1

    安装成功或已安装的用户更新到最新 brew

    brew update
    
       
       
      • 1

      检查 brew 安装情况

      ➜  ~ git:(master) ✗ brew -v           
      Homebrew 3.5.9
      Homebrew/homebrew-core (git revision a160ff052d2; last commit 2022-08-11)
      Homebrew/homebrew-cask (git revision ba90c5912b6; last commit 2022-08-10)
      
         
         
        • 1
        • 2
        • 3
        • 4

        查看当前 brew 下的安装列表

        ➜  ~ git:(master) ✗ brew list
        ==> Formulae
        bdw-gc			icu4c			nettle
        boost			isl			node
        brotli			krb5			npth
        c-ares			libassuan		openssl@1.1
        ...
        
           
           
          • 1
          • 2
          • 3
          • 4
          • 5
          • 6
          • 7

          安装配置

          安装命令

          在 terminal 执行以下命令

          ➜  ~ git:(master) ✗ brew install postgresql
          error: could not lock config file .git/config: Permission denied
          error: could not lock config file .git/config: Permission denied
          fatal: not in a git directory
          Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
          ==> Downloading https://mirrors.cloud.tencent.com/homebrew-bottles/krb5-1.20.arm
          ######################################################################## 100.0%
          ==> Downloading https://mirrors.cloud.tencent.com/homebrew-bottles/postgresql-14
          ######################################################################## 100.0%
          ==> Installing dependencies for postgresql: krb5
          ==> Installing postgresql dependency: krb5
          ...
          
             
             
            • 1
            • 2
            • 3
            • 4
            • 5
            • 6
            • 7
            • 8
            • 9
            • 10
            • 11
            • 12

            检查安装结果

            ➜  ~ git:(master) ✗ psql -V
            psql (PostgreSQL) 14.4
            
               
               
              • 1
              • 2

              配置命令

              启动 / 关闭 PostgreSQL
              • 检查服务列表,显示 PostgreSQL 未启动

                ➜  ~ git:(master) ✗ brew services list            
                Name       Status User File
                postgresql none        
                unbound    none    
                
                     
                     
                  • 1
                  • 2
                  • 3
                  • 4
                • 启动 PostgreSQL

                  ➜  ~ git:(master) ✗ brew services start postgresql                    
                  ==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
                  
                       
                       
                    • 1
                    • 2
                  • 检查执行结果

                    ➜  ~ git:(master) ✗ brew services list
                    Name       Status     User File
                    postgresql error  256 user ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
                    unbound    none    
                    
                         
                         
                      • 1
                      • 2
                      • 3
                      • 4

                      只要不是 none 就代表 已启动

                    • 关闭 PostgreSQL

                      ➜  ~ git:(master) ✗ brew services stop postgresql
                      Stopping `postgresql`... (might take a while)
                      ==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
                      
                           
                           
                        • 1
                        • 2
                        • 3
                      新建用户
                      createuser 用户名 -P
                      
                         
                         
                        • 1
                        新建数据库
                        ➜  ~ git:(master) ✗ createdb 数据库名 -O 用户名 -E UTF8 -e   
                        
                           
                           
                          • 1

                          检查现有用户及数据库

                          ➜  ~ git:(master) ✗ psql -l 
                                                       List of databases
                             Name    |    Owner     | Encoding | Collate | Ctype | Access privileges 
                          -----------+--------------+----------+---------+-------+-------------------
                           mydb      | mypsql       | UTF8     | C       | C     | 
                           postgres  | user         | UTF8     | C       | C     | 
                           template0 | user         | UTF8     | C       | C     | =c/user          +
                                     |              |          |         |       | user=CTc/user
                           template1 | user         | UTF8     | C       | C     | =c/user          +
                                     |              |          |         |       | user=CTc/user
                          (4 rows)
                          
                             
                             
                            • 1
                            • 2
                            • 3
                            • 4
                            • 5
                            • 6
                            • 7
                            • 8
                            • 9
                            • 10
                            • 11
                            建立链接
                            ➜  ~ git:(master) ✗ psql -U mypsql -d mydb -h 127.0.0.1        
                            psql (14.4)
                            Type "help" for help.
                            
                            • 1
                            • 2
                            • 3

                            mydb=> </span>q

                              声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
                              推荐阅读
                              相关标签
                                

                              闽ICP备14008679号