Blog

Thoughts from my daily grind

Managing PG with ASDF on Development

Posted by Ziyan Junaideen |Published: 29 April 2023 |Category: IT
Default Upload |

As a developer, you should maintain parity between your local development environment and the production servers. Earlier, I used Chef Solo to provision Vagrant virtual machines (on VirtualBox or VMWare), mimicking the production environment build. I have relied solely on ASDF for a few months to maintain tool versions, including PostgreSQL.

This post discusses how you can use ASDF to install and manage different versions of PostgreSQL on your development machine.

I assume you have already installed ASDF in your computer.

Preparation

Make sure you have a .tool-versions file in your project root.

❯ cat .tool-versions

ruby 3.1.2
postgres 14.2
redis 6.2.1
nodejs 16.14.2

Installation

Install dependencies.

brew install gcc readline zlib curl ossp-uuid

Export the Homebrew prefix in you .zprofile or .zshrc file. Uncomment the appropriate line and cleanup the rest.

# .zprofile
# For Apple Silicone M1, M2 etc
# export HOMEBREW_PREFIX=/opt/homebrew
# For Intel Macs
# export HOMEBREW_PREFIX=/usr/local

Then install the PostgreSQL ASDF plugin

asdf plugin-add postgres

Once you have installed the plugin, you install PostgreSQL and any related dependencies:

asdf install

This will install PostgreSQL and any other dependencies. To start and stop PG you can use:

pg_ctl start
pg_ctl stop

I would go one step further and create my self a SUPERUSER role.

psql -U postgres
CREATE ROLE ziyan SUPERUSER LOGIN CREATEDB PASSWORD '<password>'
About the Author

Ziyan Junaideen -

Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.

Comments