Skip to main content

Postgres is also an option than MySQL

Last month I got a chance to optimize some queries of a postgre sql database in my current organization. I was totally new to this database. SQL Server, mySQL, MongoDB, and now, postgres. I  never say a 'no' if some work related to database comes to me, and especially, if the database belongs to the RDBMS family, then, I can never say a 'no', as I am always keen to learn new and new trends.

My thought for postgres was wrong earlier. I used to think that it is less popular than mySQL, but, I was wrong. When I started working on it, I found it much better mySQL in some scenarios, like - query optimization(using execution plan and statistics).

Technically, Postgres is "better SQL" as it is more standardized. With better query planning, so that you can follow the relational model more closely if it suits you. Socially, MySQL has been very popular for a long time and many people are familiar with it. Postgres is neither owned by a major conglomerate with a questionable track record nor forked into half a dozen broadly similar projects.

Some differences between mySql and Postgres I consolidated from Quora , can be read from the following link :

By the way, Wiki says : PostgreSQL is developed by the PostgreSQL Global Development Group, a diverse group of many companies and individual contributors. It is free and open-source software, released under the terms of the PostgreSQL License, a permissive free-software license. Postgres, is an object-relational database (ORDBMS) – i.e. a RDBMS, with additional "object" features – with an emphasis on extensibility and standards compliance; on macOS, PostgreSQL is the default database – for web hosting and it is also available for Microsoft Windows and Linux. PostgreSQL is ACID-compliant and transactional. PostgreSQL has updatable views and materialized views, triggers, foreign keys. Supports functions and stored procedures, and other expandability.

Postgres execution plan is more detailed and deeper than mysql. See the below execution plan (Explain output) of a query.

Limit  (cost=68.72..68.84 rows=50 width=44)
  ->  Sort  (cost=68.72..69.28 rows=226 width=44)
        Sort Key: tq.TQ
        ->  Hash Left Join  (cost=35.26..61.21 rows=226 width=44)
              Hash Cond: (p.Id = tq.PlayerId)
              ->  Hash Left Join  (cost=26.66..48.37 rows=226 width=40)
                    Hash Cond: (p.Id = f2.PlayerId)
                    Join Filter: (f.FundingLineId = 2)
                    ->  Hash Left Join  (cost=17.85..35.89 rows=226 width=40)
                          Hash Cond: (p.Id = f.PlayerId)
                          ->  Hash Left Join  (cost=8.40..23.33 rows=226 width=32)
                                Hash Cond: (p.CountryId = c.Id)
                                Join Filter: (p.CountryId > 0)
                                ->  Seq Scan on players p  (cost=0.00..11.26 rows=226 width=33)
                                ->  Hash  (cost=5.40..5.40 rows=240 width=7)
                                      ->  Seq Scan on country c  (cost=0.00..5.40 rows=240 width=7)
                          ->  Hash  (cost=6.22..6.22 rows=258 width=12)
                                ->  Seq Scan on funds f  (cost=0.00..6.22 rows=258 width=12)
                                      Filter: (FundingLineId = 1)
                    ->  Hash  (cost=5.58..5.58 rows=258 width=8)
                          ->  Seq Scan on funds f2  (cost=0.00..5.58 rows=258 width=8)
              ->  Hash  (cost=5.49..5.49 rows=249 width=8)
                    ->  Seq Scan on playertq tq  (cost=0.00..5.49 rows=249 width=8)

Online tool to understand execution plan metadata in described …

Even postgres admin also given GUI like sql server for understanding there plan.

Thanks for reading


  1. Thank you so much it is actually a very nice blog written to provide adequate information about Postgre and SQL and its related aspects.

    SSIS Postgresql Write

  2. Thank you for putting up a descriptive post on a very useful aspect of SQL. This actually helped me a lot to understand this topic.

    SSIS PostgreSql Write


Post a Comment

Plz dont forget to like Facebook Page..

Popular posts from this blog

SQL71562: external references are not supported when creating a package from this platform

Last week I got this error from one of developer who was trying to deploy his project from Testing server to SQL Azure QA server. He was using “Deploy Database to SQL Azure” option from SSMS Tool-Task option. After connecting to SQL Azure portal when operation started to deployment below errors occurs. Validation of the schema model for data package failed. Error SQL71562: Error validating element has an unresolved refrence to object xx.dbo.xxxx external refrences are not supported when creating a package from this platform . Reason: The reason of the this error was; some functions of project was dependent on master database and only single database was being deploy to SQL Azure. DACFx must block Export when object definitions (views, procedures, etc.) contain external references, as Azure SQL Database does not allow cross-database external references So, this error was coming. Solution : I suggested him to create those function to locally

How to encrypt and decrypt Table data in postgres

For encrypting and decrypting , we must use the bytea data type on the column which we implement. Bcoz bytea will use the pgcrypto method by default. However, you will need to create the pgcrypto extension to enable these functions as they are not pre-defined in PostgreSQL/PPAS. Example CREATE EXTENSION pgcrypto; CREATE TABLE userinfo (username varchar(20), password bytea); >>    Inserting the data in an encrypted format INSERT INTO userinfo VALUES(' suman ',encrypt('111222','password','aes')); select * from userinfo ; >>    Retrieving the data as decrypted format SELECT decrypt(password,decode('password','escape'::text),'aes'::text) FROM userinfo; Thanks for reading Plz dont forget to like Facebook Page..

How to recover msdb database from suspect mode

 It was Monday 9 th Jun 47 degr. temperature of Delhi-NCR. Temperature was like boiling me and database. When I reached my office( @ 8.45 am) got an alert from one of Server. “MSDB is in suspected mode” At the same time comes in my mind, this issue will boil me today.. I just tried to cool my self through cold drink then connected server from my local system using windows authentication mode..