在Windows上启动PostgreSQL和pgAdmin而无需安装

37

我如何在Windows上启动PostgreSQL和pgAdmin III而无需安装?我没有系统管理员权限,因此需要在不安装应用程序的情况下启动它。我该怎么做?


也许这可以帮助您 https://www.tutlinks.com/install-postgresql-without-admin-rights-windows/ - navule
3个回答

86
  1. Download the ZIP file from https://www.enterprisedb.com/download-postgresql-binaries

  2. Unzip the archive into a directory of your choice (the archive is created such that unzipping it, it will create a directory pgsql with everything else below that)

  3. Run initdb (this can be found in the subdirectory pgsql\bin)

     initdb -D c:\Users\Arthur\pgdata -U postgres -W -E UTF8 -A scram-sha-256
    

    This will create the postgres "data directory" (aka the "cluster") in c:\Users\Arthur\pgdata. You need to make sure that the user running this command has full read/write privileges on that directory.

    -U postgres creates the superuser as postgres, -W will prompt you for the password of the superuser, -E UTF8 will create the database with UTF-8 encoding and -A scram-sha-256 enables the password authentication.

  4. To start Postgres, run:

     pg_ctl -D c:\Users\Arthur\pgdata -l logfile start
    

    this has(!) to be done as the user who ran initdb to avoid any problems with the access to the data directory.

  5. To shutdown Postgres, run:

     pg_ctl -D c:\Users\Arthur\pgdata stop
    
  6. psql.exe (the command line client) is located in the bin directory. Starting with Postgres 9.6 the pgAdmin executable pgAdmin4.exe is located in the sub-directory "pgAdmin 4\bin".

  7. Optionally create a Windows service to automatically run Postgres (must be run using a Windows administrator account)

     pg_ctl register -N postgresql -D c:\Users\Arthur\pgdata 
    

1
对于那些使用 postgresql-10.4-1-windows 的人来说,pgAdmin4将无法连接到应用程序服务器。postgresql-9.6.9-1-windows没有这个问题。 - VCD
@SolomonUcko:四年前没有更好的方式 - user330315
1
@SolomonUcko:请查看手册:https://www.postgresql.org/docs/current/client-authentication.html - user330315
创建目录 c:/Users/Arthur/pgdata... initdb: 错误: 无法创建目录 "c:/Users/Arthur": 权限被拒绝。 - Hasan A Yousef
1
@erik-stengel:我更新了我的回答。 - a_horse_with_no_name
显示剩余6条评论

2
谢谢。这对我有用。但是,我在启动psql.exe时遇到了错误。
错误提示为“psql:FATAL:role [user]不存在。”
为了解决这个问题,我按照以下步骤操作:
  1. 进入相同的文件夹路径(您拥有initdb.exe的位置),即源文件夹/pgsql/bin
  2. 运行“psql-U postgres”。这将要求输入密码。
  3. 现在输入在postgres初始化期间设置的密码。这将打开psql命令提示符。
希望这可以帮助您。 :)

2
我尝试了上述方法,它运行得很好。但是当我尝试通过JDBC连接时,我会收到以下错误提示:“认证类型10不受支持。请检查您是否已配置pg_hba.conf文件以包括客户端的IP地址或子网,并且它正在使用驱动程序支持的身份验证方案。”这是因为scram-sha-256存在一些问题(参见此处),我无法深入理解,所以我将其更改为md5,所有事情都开始顺利进行。希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接