Databases: SQLite vs PostgreSQL

Kyle Farmer
Oct 18, 2020 · 6 min read
creative commons

Databases have been used by computers for decades; since 1960 to be exact — when the first one was developed by Charles W. Bachman while working for General Electric. Before database management systems existed, everything was being stored on paper! A database management system (now simply referred to as a database) is essentially a large collection of data that is stored and organized for rapid search and retrieval by a computer. Though they may seem boring, databases keep the world running. Two of the most popular databases used today are SQLite (“sequel-lite”) and PostgreSQL (“post-gres-sequel”). Let’s take a closer look at the applications, similarities and differences between the two.

wikipedia

SQLite was created in the year 2000 by D. Richard Hip. He developed it while he was contracted by the US Navy to design software for a damage-control system aboard guided-missile launchers(!!). The goal was to allow the program to operate without having to install a database management system, but rather use a standalone, embedded database. Thus the ultra lightweight SQLite was designed to solve the problem. According to D. Richard Hip’s on his twitter account “The original use-case for SQLite was in a damage-control system. SQLite was built to save lives, not blow things up.”

SQLite is one of the most widely used, open-source, relational databases in the world. It is simple to use, even for most beginners. Ruby on Rails and many web browsers use SQLite as their default database. SQLite is serverless — this is to say that the database runs on the same disk as the application using it — basically, it runs within the application. This means there is no setup or installation that has to be done to get the database up and running; SQLite it is often referred to as requiring “zero-configuration”. The small footprint of its library (just under 600kb) makes it an easy choice for compact, lightweight apps where space is a valuable commodity. It is coded in C and uses SQL as its query language, though not all SQL statements are compatible. SQLite is weakly typed ("flexibly typed” is the preferred term according to the SQLite website). This means a string of “1234” can be inserted into an integer column and SQLite will convert between formats to the best of its ability. However, if a non-numeric string is entered into an integer column, SQLite will not throw an error but will instead store the data as a string. This is viewed by SQLite as a feature, not a bug.

wikipedia

PostgreSQL (originally named POSTGRES) has been around a good bit longer than SQLite with the first iteration of it being developed in 1985 by a team at the University of California, Berkeley. Their goal was to create a database that used the fewest features needed to support the most common data types. The database understood relationships and could retrieve information in related tables using rules. In 1996 the project was officially renamed to PostgreSQL to better reflect its support for SQL since 1994. It is a free, open-sourced, object relational database. Like SQLite, it is coded in C and uses SQL as its query language to operate. PostgreSQL is server based, which means it communicates by sending and receiving data in a client-server model using TCP/IP. The client and the server can be on different hosts but connected to each other by using the same network. This makes it a great choice for handling multiple users. However, some configuration and setup is required before use. PostgreSQL is best suited when a complex, customizable and reliable database is needed.

Some other differences in the two databases are as follows: While SQLite does support multiple users, only one user can write to the database at a time, as the database briefly locks when it is written to. PostgreSQL allows multiple users to access the database at the same time and they can perform operations simultaneously. It also features a robust user management system that allows different clearances and permissions to be given to users. SQLite does not have a user management system. When it comes to simple operations, SQLite can perform much faster than PostgreSQL due to its simple lightweight design. However, SQLite can only perform one write operation at a time as mentioned, whereas PostgreSQL can handle multiple simultaneous operations. So when operations get complex, SQLite operates much slower than PostgreSQL. SQLite only supports 5 common data types, while PostgreSQL supports nearly all of them — see the extensive list here: https://www.tutorialspoint.com/postgresql/postgresql_data_types.htm

Both databases are ACID compliant (atomicity, consistency, isolation, durability). Basically, this means that data consistency is guaranteed despite errors such as crashes, power failures, etc. ACID ensures that the entire data “transaction” (a sequence of operations that make up one logical unit of work) that takes place all at once or else it doesn’t happen at all. Think of it like a bank transfer or getting money out of an ATM — either the transaction is 100% completed or it doesn’t happen at all. All transactions are isolated and not visible to any other transactions until they have been fully executed. The ACID acronym was coined in 1983 by Andreas Reuter and Theo Härder; however, the practice had been in use by IBM since 1973.

Ultimately, you should let your application and not your personal preference dictate which database is suited for your needs. If you are making a small, single user app go with SQLite. If you are making something that is going to require large volumes of data, good security, network access, and multiple users, you should use a server based database, such as PostgreSQL. Both databases have their own strengths and weaknesses which help to serve unique needs that each application will have.

DISCLAIMER: I’m in a software coding bootcamp and have only been working with databases for about 3 weeks. I wrote this in an attempt to better understand the different abilities and uses of databases.

Resources for this article listed below:

https://www.tecmint.com/what-is-postgresql-how-does-postgresql-work/

https://www.tutorialspoint.com/postgresql/postgresql_overview.htm

The Startup

Get smarter at building your thing. Join The Startup’s +785K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Kyle Farmer

Written by

Former live music audio engineer. Recent bootcamp grad, current job seeker.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +785K followers.

Kyle Farmer

Written by

Former live music audio engineer. Recent bootcamp grad, current job seeker.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +785K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store