Installing PostgreSQL on macOS
Serhii Shramko /
Title: Installing PostgreSQL on macOS: A Step-by-Step Guide
Are you looking to set up a powerful and reliable relational database system on your macOS machine? PostgreSQL, also known as Postgres, is an excellent choice. It's a popular open-source database that offers robust features and scalability. In this guide, we'll walk you through the steps to install PostgreSQL on your macOS system.
First, let's ensure that you have Homebrew, a package manager for macOS, installed on your system. If you don't have it already, you can install it using the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
With Homebrew in place, we can now proceed to install PostgreSQL. Open your terminal and run the following command:
brew install postgresql
Homebrew will fetch and install PostgreSQL along with its dependencies. This process may take a few minutes.
After the installation is complete, you can start the PostgreSQL server with the following command:
brew services start postgresql
To stop the PostgreSQL server when you're done, use:
brew services stop postgresql
Now that PostgreSQL is up and running, you can create your first database. Use the following command to access the PostgreSQL interactive terminal:
You can create a new database with the following SQL command, replacing
mydatabase with your desired database name:
CREATE DATABASE mydatabase;
You can access PostgreSQL using various database clients and tools, or you can continue to use the terminal. To connect to your newly created database, use:
psql -d mydatabase
By default, PostgreSQL is installed without a password. It's highly recommended to set a password for the
user to enhance security. To do this, run:
psql ALTER USER postgres PASSWORD 'yourpassword';
yourpassword with a strong password of your choice.
Congratulations! You've successfully installed PostgreSQL on your macOS system. You're now ready to create, manage, and interact with relational databases using this powerful and versatile database management system.
Remember to consult the PostgreSQL documentation and official resources for more advanced configuration and usage options. Happy database management!