Saving the output of a PostgreSQL query to text file

Saving an output of PostgreSQL query to a text file

When using PostgreSQL on Linux, there may be times that you wish to save the output of a query. Normally, the output appears on your screen. It’s possible to redirect this output to a file instead, which would allow you to view it later. In this guide, we’ll show you how to save the output of a PostgreSQL query to a file.

In this tutorial you will learn:

  • How to save the output of a PostgreSQL query to a file

Read more

Verifying changes with grep

How to create a hot standby with PostgreSQL

Objective

Our objective is to create a copy of a PostgreSQL database that is constantly synchronizing with the original one and accepts read-only queries.

Operating System and Software Versions

  • Operating system: Red Hat Enterprise Linux 7.5
  • Software: PostgreSQL server 9.2

Requirements

Privileged access to both master and slave systems

Read more

PostgreSQL performance tuning for faster query execution

Objective

Our objective is to make a dummy query execution run faster on PostgreSQL database using only the built in tools available
in the database.

Operating System and Software Versions

  • Operating System: Red Hat Enterprise Linux 7.5
  • Software: PostgreSQL server 9.2

Requirements

PostgreSQL server base install up and running. Access to the command line tool psql and ownership of the example database.

Read more

Results of running the application

How to persist data to PostgreSQL in Java

Java is perhaps the most widely used programming language nowadays. It’s robustness and platform-independent nature enables Java based applications to run on mostly anything. As is the case with any application, we need to store our data in some sort of reliable way – this need called databases to life.

In Java database connections are implemented by JDBC (Java Database Connectivity API), that let’s the programmer handle different kind of databases in almost the same way, which makes our lives much easier when we need to save or read data from a database.

In this tutorial we will create an example Java application that will be able to connect to a PostgreSQL database instance, and write data into it. To check that our data insertion is successful, we’ll also implement reading back and print the table we inserted data into.

In this tutorial you will learn:

  • How to setup the database for the application
  • How to import PostgreSQL JDBC Driver into your project
  • How to insert data into the database
  • How to run a simple query to read a database table’s content
  • How to print fetched data

Read more

Install PostgreSQL on Ubuntu 18.04 Bionic Beaver

Objective

The objective is to Install PostgreSQL server or client on Ubuntu 18.04 Bionic Beaver

Operating System and Software Versions

  • Operating System: – Ubuntu 18.04 Bionic Beaver
  • Software: – PostgreSQL Server 10

Requirements

Privileged access to your Ubuntu System as root or via sudo command is required.

Conventions

Read more

Ubuntu 20.04 PostgreSQL

Ubuntu 20.04 PostgreSQL Installation

PostgreSQL is a database management system, similar to MySQL in many respects but with some key differences. Like MySQL, it’s commonly hosted on Linux. In this guide, we’ll show how to run a PostgreSQL server on Ubuntu 20.04 Focal Fossa, as well as installing the client version in case you just need to connect to an external PostgreSQL database.

In this tutorial you will learn:

  • How to install PostgreSQL Client and connect to a server
  • How to install and configure PostgreSQL Server

Read more

Recording data trough browser

Persisting data into a PosgreSQL database with PHP

PHP is a widely used server scripting language. It’s vast capabilities and lightweight nature makes it ideal for web frontend developing, and while it is possible to create advanced structures in it, it’s basic usage also easy to learn, which makes it a good starting point for beginners also. The data recorded, processed, sent or displayed by the application we build is need to be stored somewhere, however; our webpage is stateless without this data. We can store our data in many ways or even discard it after use, but the most standard way is storing it in a database designed for the sole purpose of storing data in a reliable way, and present it if needed, as fast as possible.

In this tutorial we will build a simple webpage to record and display user data. We will use a PostgreSQL RDBMS as backend, and develop our application in PHP that will run on an Apache Webserver. This way we can access our web application from any common browser to view or add to our user database. It is the nature of the web application that many users/operators can work with it simultaneously, all they need is a browser and network access to our application.

In this tutorial you will learn:

  • How to install needed packages for PostgreSQL connection in PHP
  • How to create the database side of the application
  • How to code the example application
  • How to operate and verify the example application

Read more

Initializing and accessing PostgreSQL database on Red Hat Enterprise Linux 8

How to install PostgreSQL server on RHEL 8 / CentOS 8

PostgreSQL is an free-opensource object-relational database management system. The objective of this tutorial is to perform an installation and basic configuration of PostgreSQL server on RHEL 8 / CentOS 8 Linux server.

In this tutorial you will learn:

  • How to install PostgreSQL database server on RHEL 8 / CentOS 8
  • How to start and enable PostgreSQL database server
  • How to access PostgreSQL database from localhost and remote location
  • How to set password for the default postgres user
  • How to enable PostgreSQL to listen on all networks
  • How to secure PostgreSQL remote connection with MD5 password authentication
  • How to open PostgreSQL firewall port
  • How to establish remote connection to PostgreSQL server using psql client

Read more