Instructions for installing PostgreSQL DBMS
The following instructions for installing PostgreSQL are based on macOS.
For Windows and Linux, go tohttps://www.postgresql.org/download/And select your package.
Also search for "How to install Postgres on Windows" or "How to install postgres on Windows".
your linux distribution"(If you are using another platform).
It should be the same, especially after the installation phase.
When finished, go back and run in the command line:
brew install postgresql
And when it's finished, run:
brew services start postgresql
TobeginPostgreSQL acts as a daemon, which means it will continue to run in the background to monitor connections.
The huge advantage of using Homebrew is that you can install any updates by running the following command
brew upgrade postgresql brew postgresql-upgrade-database brew services restart postgresql
postgresqlThe name of PostgreSQL is more complicated, but they are the same thing. It just embeds SQL in the name. what isSQL? SQL (called "sequel") stands for Structured Query Language, it is a special language that we use to communicate withRelational Database.
If you are new to databases, this is a lot of new terms for you! Basically, relational databases organize data intotable, And provides a way to insert and extract data from these tables. That is SQL.
We will use it soon.
After we log in to PostgreSQL!
Return to the command line and type
This will enable you to access
postgresThe database created with your macOS username is used by default. Homebrew will automatically create your user during installation.
Now we enter
psqlApplication, we can create a new database:
CREATE DATABASE test;
Don't forget the semicolon
;, Because SQL requires it, otherwise the command will not run.
Now in the new line, we use the following command to switch to that database
The prompt will display the following:
You are now connected to database "test" as user "flaviocopes"..
Now we will create a new table.
Use the following syntax:
CREATE TABLE users ( id SERIAL PRIMARY KEY, email VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL );
Now, if you run this command and no errors are displayed, the table will be included in the system.
You can view it by running the command
This will show you the database tables:
If any errors occur, you can delete the table by running the following command
DROP TABLE users
Or just type
Now that you know the behind-the-scenes knowledge of things, I will show you an easier way to use PostgreSQL and other databases:TablePlus application. It is suitable for macOS, Windows and Linux.
Connect to the database:
In addition to being able to use the graphical user interface checklist:
It also allows us to use SQL queries very easily:
More database tutorials:
- MongoDB basic tutorial
- How is MongoDB different from SQL database
- Information system, data and information
- Data model
- Introduction to ER data model
- Relational model
- Relational algebra
- relational database
- What is a database? There is also a DBMS?
- Introduction to SQL
- How to install PostgreSQL on macOS
- Do you always need to provide a database for the application?
- How to install SQLite on macOS
- Introduction to PostgreSQL
- PostgreSQL user permissions
- How to list all users in PostgreSQL
- How to switch database using PostgreSQL
- How to list all databases using PostgreSQL
- How to use PostgreSQL to list the tables in the current database
- How to install MySQL on macOS
- Create user on MySQL
- PostgreSQL vs MySQL, comparison
- SQLite user permissions
- MySQL user permissions
- SQL, create table
- SQL, add data to the table
- SQL, how to use SELECT
- SQL, handle empty cells
- SQL, unique key and primary key
- SQL, how to update data
- SQL, how to update the table structure
- SQL, how to delete data and tables
- SQL connection
- SQL view
- How to insert multiple items in a MongoDB collection at once
- How to delete all items from MongoDB collection