scoop安装使用PostgreSQL

安装PostgreSQL过程

D:\software\scoop\apps>scoop install postgresql
Installing 'postgresql' (18.1) [64bit] from 'main' bucket
Loading postgresql-18.1-1-windows-x64-binaries.zip from cache.
Checking hash of postgresql-18.1-1-windows-x64-binaries.zip ... ok.
Extracting postgresql-18.1-1-windows-x64-binaries.zip ... done.
Linking D:\software\scoop\apps\postgresql\current => D:\software\scoop\apps\postgresql\18.1
Creating shortcut for pgAdmin 4 (pgAdmin4.exe)
Adding D:\software\scoop\apps\postgresql\current\bin to your path.
Persisting data
Running post_install script...done.
'postgresql' (18.1) was installed successfully!
Notes
-----
Run 'pg_ctl start' to start the database and 'pg_ctl stop' to stop it.
Register it as a service by running 'pg_ctl register -N PostgreSQL' from an elevated shell.
Default superuser login: postgres, password: <blank>

安装PostgreSQL服务(可选)

通过上面的安装过程给出了PostgreSQL启动和停止的命令pg_ctl startpg_ctl stop,默认的超级用户postgres,密码为空。
下面我们给PostgreSQL安装系统服务,便于随时启停。管理员运行cmd运行下面的命令。

# 添加服务
pg_ctl register -N PostgreSQL
# 添加服务的描述
sc description PostgreSQL "5432端口运行PostgreSQL服务"
# 设置手动启动。delayed-auto:自动(延迟启动) auto:自动 demand:手动 disabled:禁用服务
sc config PostgreSQL start=demand

启停脚本(可选)

由于我经常忘记要如何启停服务,所以写了一个脚本,方便点击来启停。

@echo off
::获取管理员权限
net session >nul 2>&1 || powershell -NoP -C "Start-Process -FilePath '%~f0' -Verb RunAs" && exit

:start
mode con cols=55 lines=20
title PostgreSQL小工具
echo ***************************************************
echo  1.开启PostgreSQL   2.关闭PostgreSQL    3.退出
echo ***************************************************
echo.
set /p option=请输入你的选择:
echo.
if "%option%"=="1" net start PostgreSQL
if "%option%"=="2" net stop PostgreSQL
if "%option%"=="3" goto byebye
:: 等待3S回到菜单
timeout /t 3
cls
set option=null
goto start

:byebye
echo See you.
ping -n 2 127.0.0.1>nul
exit
pause
posted @ 2025-11-17 03:28  雨中遐想  阅读(19)  评论(0)    收藏  举报