Для установки PostgreSQL на MacOS будем использовать brew (очень популярный менеджер пакетов в MacOS) для простоты.
Давайте посмотрим какие сервисы уже установлены и менеджатся через brew с помощью команды brew services
:
% brew services Name Status User File memcached none nginx none php none php@8.2 none postgresql@16 none
Установка postgresql на MacOS через brew
brew install postgresql
В результате установки, новый сервис postgresql будет доступен. Пример вывода команды установки postgresql через brew:
% brew install postgresql ==> Auto-updating Homebrew... Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`). ==> Downloading https://ghcr.io/v2/homebrew/portable-ruby/portable-ruby/blobs/sha256:49847c7a13f7094b211f6d0025900dd23716be07dac894a3d6941d7696296306 ############################################################################################################ 100.0% ==> Pouring portable-ruby-3.3.3.arm64_big_sur.bottle.tar.gz ==> Auto-updated Homebrew! Updated 4 taps (homebrew/services, redis-stack/redis-stack, homebrew/core and homebrew/cask). ==> New Formulae age-plugin-se chsrc ecs-deploy kubevpn otree testscript ansible@9 codecov-cli egctl lando-cli porter tinymist asak cyctl envelope libpeas@1 poutine toipe awsdac cyme geni llgo pulsarctl topfew batt dep-tree gensio mako qrtool typstyle chkbit dnsgen kubelogin nsync subliminal zfind ==> New Casks ball font-gulimche getoutline charmstone font-gungsuh impel clash-verge-rev font-gungsuhche inkdown ea font-maname itermai elgato-capture-device-utility font-palemonasmufi-bold k8studio emclient@beta font-palemonasmufi-bolditalic lazycat font-alumni-sans-sc font-palemonasmufi-italic loop font-batang font-palemonasmufi-regular macsymbolicator font-batangche font-playwrite-ar material-maker font-beiruti font-playwrite-at monokle font-big-shoulders-display-sc font-playwrite-be-vlg navicat-premium-lite font-big-shoulders-inline-display-sc font-playwrite-be-wal orka-desktop font-big-shoulders-inline-text-sc font-playwrite-cl pia font-big-shoulders-stencil-display-sc font-playwrite-cu plugdata@nightly font-big-shoulders-stencil-text-sc font-playwrite-cz positron font-big-shoulders-text-sc font-playwrite-dk-loopet productive font-dotum font-playwrite-dk-uloopet proton-pass font-dotumche font-playwrite-hr retroarch-metal@nightly font-edu-au-vic-wa-nt-hand font-playwrite-hr-lijeva tella font-fragment-mono-sc font-playwrite-hu vcam font-fustat font-playwrite-pe wd-security font-ga-maamli font-wittgenstein xnapper font-gulim font-zain yaak You have 28 outdated formulae and 3 outdated casks installed. Warning: Formula postgresql was renamed to postgresql@14. ==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/14/manifests/14.12 ############################################################################################################ 100.0% ==> Fetching postgresql@14 ==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/14/blobs/sha256:8e468dba4092ff6c8af082517894e9a2ffaa9c2 ############################################################################################################ 100.0% ==> Pouring postgresql@14--14.12.arm64_sonoma.bottle.tar.gz ==> /opt/homebrew/Cellar/postgresql@14/14.12/bin/initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14 ==> Caveats This formula has created a default database cluster with: initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14 For more details, read: https://www.postgresql.org/docs/14/app-initdb.html To start postgresql@14 now and restart at login: brew services start postgresql@14 Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14 ==> Summary /opt/homebrew/Cellar/postgresql@14/14.12: 3,322 files, 45.6MB ==> Running `brew cleanup postgresql@14`... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Для старта сервиса postgresql выполнить:
brew services start postgresql
Примерный вывод команды:
% brew services start postgresql Warning: Formula postgresql was renamed to postgresql@14. ==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
Как видим, сервис postgresql (в данном случае v14) успешно стартанул.
Мы можем это проверить командой brew services
Создание пользователя и базы данных
При установке Postgresql через brew, автоматически создается пользователь без пароля с тем же именем как ваш username в macOS. Давайте сейчас проверим, можем ли подключиться к postgres из консоли и создадим нового пользователя и базу данных.
Тут все аналогично созданию пользователя в Linux в postgresql.
Комментарии 0