Setting up local postgres database for noobs like me

I needed a little extra push beyond the docs for figuring out how to connect and migrate postgres. Sharing my steps below (on ubuntu with postgres installed).

  1. Follow this up to “Migrations” Docs - Local Postgres Setup : RedwoodJS Docs
    Example connection added at .env at project root:
DATABASE_URL="postgresql://postgres@localhost:5433/my_database_dev?connection_limit=1"
  1. Start postgres service
service postgresql start
  1. Enter postgres client
psql -U postgres

(if using default role ‘postgres’, otherwise PASSWORD=<password> psql -U <role> )

  1. Create database once inside (use database name from step 1)
postgres=# CREATE DATABASE my_database_dev;
  1. Connect to db
PASSWORD=password psql -U postgres -d my_database_dev -h 0.0.0.0 -p 5433
  1. Finally migrate and serve
yarn rw db up
yarn rw dev

… and just in case you need to reset your default postgres password like me: How To Reset Forgotten Password Of postgres User

6 Likes

Is this THE Claire from my Mintbean class? :slight_smile: Welcome!

Thanks for this! This is one of the reasons we went with new projects starting out of the box with just SQLite in development—initial Postgres setup is kind of a pain, especially if you’re not used to running your own database. :confused:

If someone were to open a PR to the official docs with these additional steps it would be happily accepted and they would have our undying gratitude… :wink: And that person would get to experience the power of CameronJS!

2 Likes

Thank you for posting about it! :mechanical_arm:

Is this only for ubuntu or does this work on other linux repos aswell?

1 Like

@Chris i am too noob to answer that haha. My guess is it should work on any debian distro… don’t take my word for it

1 Like

For macOS people, I have been using a version of the thoughtbot laptop setup script for several years each time i’m lucky enough to get a new machine.

It installs “pretty much” most things you need to get up and running for development – including a PG database (done through homebrew).

Really handy.

What it sets up

macOS tools:

  • Homebrew for managing operating system libraries.

Unix tools:

  • Universal Ctags for indexing files for vim tab completion
  • Git for version control
  • OpenSSL for Transport Layer Security (TLS)
  • RCM for managing company and personal dotfiles
  • The Silver Searcher for finding things in files
  • Tmux for saving project state and switching between projects
  • Watchman for watching for filesystem events
  • Zsh as your shell

Heroku tools:

GitHub tools:

  • Hub for interacting with the GitHub API

Image tools:

Programming languages, package managers, and configuration:

  • asdf-vm for managing programming language versions
  • Bundler for managing Ruby libraries
  • Node.js and npm, for running apps and installing JavaScript packages
  • Ruby stable for writing general-purpose code
  • Yarn for managing JavaScript packages

Databases:

  • Postgres for storing relational data
  • Redis for storing key-value data

It should take less than 15 minutes to install (depends on your machine).

4 Likes

Y’know could make a custom script via

Your ~/.laptop.local is run at the end of the Laptop script. Put your customizations there

to install a dev-ready Redwood laptop which some additions like:

@dthyresson could redwood cli tool be extended to include installing postgress automatically? using scripts if asked to?

@Chris Unfortunately it’s not as easy as one would hope on Windows to get something like that working. We’re getting there, but it’s still probably going to be a year until it’s at a point where all Windows users can use it. https://devblogs.microsoft.com/commandline/windows-package-manager-preview/

Not sure that is the best way – especially if trying to be platform agnostic as @Tobbe notes.

Installing postgres with homebrew is a one liner:

brew "postgres", restart_service: :changed