The right way to get started with PostgreSQL
PostgreSQL, a free, feature-rich and extensible open-source database system with a large community of developers, has become one of the most widely used databases in the world, providing enterprise-grade features suitable for mission-critical systems at heavy load.
As with all database systems, anyone new to PostgreSQL can benefit from a clear, step-by-step approach to building a solid skill set. This article describes such an approach, which is also covered in much more detail – including step-by-step instructions and sample code – in “Postgres. The First Experience”, a free downloadable book by Pavel Luzanov, Egor Rogov and Igor Levshin.
1. Getting Started – Installation on Linux and Windows
Depending on your operating system, PostgreSQL installations differ, so it’s important to access instructions specific to your environment. For easier deployment, you can use the Postgres Pro Standard 12 or 13 distribution, which is fully compatible with vanilla PostgreSQL and available on Microsoft Azure Marketplace.
Once you’ve downloaded PostgreSQL, you can run the installation wizard, following the advice of the downloaded instructions as you go.
2. Connect to a server
In Postgres, connecting to a server requires using the psql client from the command line in interactive mode. While many developers dislike the idea of a CLI anymore, using it for Postgres makes sense because it’s available in all versions of Postgres, and it comes in handy for day-to-day DBA tasks, such as writing small queries and automating processes.
If you prefer a graphical user interface (GUI), you can try pgAdmin or another downloadable solution. pgAdmin can make it easier to perform certain DBA tasks, including reviewing database objects and performing SQL queries, and the latest version includes standard PostgreSQL utilities, system catalog information, administration functions, and SQL commands. It also has a built-in PL/pgSQL debugger which is useful to learn.
3. Practice on a demo SQL database
A demo SQL database is the best way to learn the basics of using Postgres. To take it to the next level and learn how to create complex queries, create a demo database with at least eight tables and populate it with usable data. You can also download a free, pre-populated demo database.
4. Use PostgreSQL with your application
Once you’ve mastered the basics of Postgres, you can create your application’s database. However, do not use the “database user” created during the application installation process as this user has superuser privileges. Instead, create a new user and make it the owner of a separate database, so that its rights are limited to that database instance only.
You can then follow the general instructions to connect to a new database on behalf of the new user. Once this connection is established, you are ready to develop an application with the basics of the client-server relationship in mind. Whether to localize the business logic of the application on the server side, client side, or a bit of both will depend on your knowledge and future needs.
5. Minimum Server Requirements
Although PostgreSQL’s default settings work on almost all hardware configurations, you’ll get better performance if the database configuration is based on the physical characteristics of the server and typical application workload. To ensure optimal performance for production databases, most DBAs take a deep dive into PostgreSQL database administration, including taking online or in-person courses.
6. Postgres includes a number of advanced features that can enhance the capabilities of your applications:
- Full-Text Search – This feature allows you to search textual data in a Big Data database using a relevance algorithm – similar to how Google search works.
- JSON and JSONB – The simplicity of NoSQL databases – the lack of a fixed row-and-column-oriented structure – provides enormous speed, but these databases are insufficient for sophisticated database work. JSON and JSONB bring some of the speed benefits of NoSQL to SQL without breaking the traditional SQL database structure.
- Foreign Data Wrappers – To allow Postgres-based applications to share data with other applications, PostgreSQL supports ISO/IEC 9075-9 (SQL/MED, Handling External Data), which defines how to work with external data sources through a mechanism called foreign data wrappers. Postgres includes two external data wrappers, one for external PostgreSQL databases and one for files on a server. Foreign data wrappers for Oracle, MySQL and SQL Server are also available as extensions.
- The PostgreSQL 13 release also includes key new features, including b-tree deduplication, incremental sorting, parallelized vacuum, and improved partitioning.
- The most recent version, PostgreSQL 14, includes enhancements for greater scalability, extensibility, and usability and introduces several performance enhancements for parallel queries, heavily concurrent workloads, partitioned tables, logical replication, and scavenging.
For a complete list of PostgreSQL features, see the PostgreSQL Feature Matrix.
The more you learn about PostgreSQL upfront, the more you can optimize your applications from scratch — and the more valuable you will become to your organization. You can also follow expert blogs and the availability of free webinars. Keep in mind that PostgreSQL version 14 is on the horizon and includes many improvements, some of which may impact an eventual migration.
About the Author
Igor Levshin is Chief Content Officer of Postgres Professional, the company that makes PostgreSQL enterprise-ready.
Sign up for the free insideBIGDATA newsletter.
Join us on Twitter: @InsideBigData1 – https://twitter.com/InsideBigData1