Introduction to PostgreSQL
PostgreSQL is an object-relational database management system. To understand this statement you should be aware of the object model and the relational model. Relational databases rely on the relational model. They store data in tables as rows and columns. Object-oriented databases store data as objects. Object-relational databases are a composition of the above two. Object-relational databases stores data as a traditional relational database. But there is the support to access the data as objects via API’s. There are examples for relational database systems such as MySQL.Also, there are examples for object-oriented database systems such as MongoDB.
If you haven’t heard about Postgres before you now should have a question of why Postgres. Why is this any different from the databases that we have heard of like MySQL? I had the same problem. From all the things I heard, I came up with the following example. Let’s say you own a jeep and a bicycle. When your mother asked you to go to the shop nearby to buy something what would you choose as your mode of transport?
Almost everyone will choose the bicycle. But why? Jeep is great it has good seats supports any terrain. many use cases but at the same time, it is a bit costly choice when compared to a bicycle. When selecting the bicycle intentionally or unintentionally you select the low-cost mechanism that suits your use case. When coming back to our topic Postgres is something that is similar to the 4*4 Jeep. It is complex. Has many use cases. Has many functions. Supports large databases. Good for complex analytics. But at the same time, it is costly. MySQL is something similar to the bicycle. For simple use cases, it does the job. But it might not be the best choice for complex use cases. So the bottom line is if you are using Postgres then you should have a matching complex use case. Otherwise, it is a waste of resources.
How to Install Postgres
There are many ways to install Postgres but I have tried two and the most easier way is to use brew to install Postgres. You just need to type
brew install postgres
and brew will do the rest. Another option is to use Docker. This is also a great way of using Postgres without making your file system ugly. You can go to Docker Hub and find a relevant Postgres image and try really easily.
If you used brew you can set Postgres to run every time when the computer starts. Or start using brew.
To make sure it starts every time your computer starts. Execute the following command
pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
Or if you want you to start by your self every time.
brew services start postgresql
To make sure Postgres start and running
postgres -V
Postgres Features
- Unlike pure relational databases, Postgres has some concepts from object-oriented programming. So unlike pure relational databases, Postgres supports complex data structures.
- It has custom data type support
- It does not have a maximum database size.
- Multiple readers and writers can access the same database at the same time. This is called as Multi-version concurrency control. (MVCC)
- Good for complex analytics.
- In most cases queries are simmilar to MySQL queries.
- Has inbuilt support to B-tree, hash index.