Tuesday, March 21, 2023
No Result
View All Result
Get the latest A.I News on A.I. Pulses
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing
No Result
View All Result
Get the latest A.I News on A.I. Pulses
No Result
View All Result

10 Command-Line Utilities in PostgreSQL

February 13, 2023
144 6
Home Data science
Share on FacebookShare on Twitter


February 13, 2023

On this tutorial, uncover the PostgreSQL Shopper Functions, and be taught ten of the most-useful command-line instruments.

Once you determined to work with PostgreSQL databases, you most likely used graphical person interfaces equivalent to PGAdmin, DBeaver, and even paid ones like DataGrip. These software program purposes present user-friendly interfaces for working extra successfully with databases, and so they positively make database administration a lot simpler for database directors. However there’s a sturdy set of instruments known as PostgreSQL Shopper Functions that actually will leverage your effectivity whereas working with PostgreSQL databases. The excellent news is that these precious instruments are bundled and include the PostgreSQL set up bundle totally free.

The PostgreSQL Shopper Functions deliver a speedy and highly effective set of command-line instruments to the desk to make interacting with the PostgreSQL servers throughout platforms, native or distant, extra thrilling. On this tutorial, we’re going to uncover the PostgreSQL Shopper Functions and learn to get essentially the most out of them by discussing ten of essentially the most helpful command-line instruments.

We assume you already know the basics of SQL, together with the fundamentals of working with database administration methods. In case you’re unfamiliar with these or desperate to brush up in your SQL expertise, you would possibly wish to attempt our SQL Fundamentals Ability Path — Dataquest. We additionally assume you will have already put in PostgreSQL in your pc; should you haven’t, please discuss with the official PostgreSQL web site to obtain and set up it from right here.

PostgreSQL Shopper Functions

As I discussed, this bundle accommodates totally different instruments that help database directors and knowledge specialists in getting essentially the most out of PostgreSQL databases hosted on a neighborhood server, throughout networked servers, or within the cloud platforms. These command-line utilities, obtainable for Home windows, MacOS, and Linux working methods, are designed to work with and handle database objects. There are specific software units for creating and eradicating databases, roles, and customers. There are additionally some precious instruments for making and restoring backups of databases.

Nonetheless, amongst these utilities, the choose of the litter is the psql command-line software, which permits us to connect with databases, discover their contents, execute SQL queries, and output the outcome units in varied codecs. This utility can be a sport changer for leveraging the capabilities of PostgreSQL.

The psql Shopper Utility

Let’s begin exploring the PostgreSQL Shopper Functions with the psql command-line utility and its totally different choices.

However earlier than beginning work with this utility, let’s examine the PostgreSQL model put in in your native pc by operating the next command:

% psql –version

psql (PostgreSQL) 14.5 (Homebrew)

The PostgreSQL model put in on my MacBook is 14.5, which permits me to connect with any PostgreSQL server that’s operating model 14.5 or earlier.

1. Hook up with a Database

Step one to moving into the psql command-line software is to connect with a neighborhood or distant PostgreSQL server.

To hook up with a PostgreSQL database, you should use the command template:

psql –host HOSTNAME –port PORT –user USERNAME –dbname DATABASE_NAME

The HOSTNAME is a distant server title or its IP handle. If the PostgreSQL server is operating in your native machine, you should use localhost as a substitute of a server’s IP handle.

You additionally have to determine the communication port with –port. The default communication port is 5432. It’s possible you’ll omit the –port PORT argument if the port quantity is 5432.The –dbname and –username decide the database title to connect with and the username to attach with, respectively.

The next psql command makes a connection to the mydb database with username postgres that resides on the identical pc that you’re engaged on, localhost.

% psql –host localhost –port 5432 –dbname mydb –username postgres

Executing the command above opens up a connection to the PostgreSQL server operating in your native pc, and the command immediate will likely be modified as follows:

mydb=#

Now, you’ll be able to run psql‘s meta-commands, which we’ll talk about quickly. In the meantime, let’s shut the connection to the PostgreSQL server by typing q and urgent Enter, which can return you to the working system command immediate.

mydb=# q

Meta Instructions

The psql utility affords an important characteristic known as meta, or backslash, instructions. These instructions or directions are processed by the psql consumer software straight and never executed by the PostgreSQL server. The meta-commands present a wide range of choices. We’ll be taught extra about them within the following sections.

One of many meta-commands is q, which we tried earlier to stop the psql surroundings.Additionally, to get a listing of all obtainable meta-commands, you’ll be able to sort ? and press Enter.

mydb=# ?

2. The l Meta-Command

The l meta-command permits you to record all of the databases saved on the PostgreSQL server you might be linked to. First, hook up with the database server, after which run the l meta-command, as proven within the picture under. The command lists all of the obtainable databases together with all the main points.

ua6zHO1.png

3. The dt Meta-Command

We’ve linked to the mydb database; now we’re considering itemizing all the present tables on this database. To take action, you should use the dt meta-command as follows:fnKXVH8.png

As proven within the picture above, all of the database’s relations (tables) are listed with helpful particulars equivalent to schema and the proprietor of tables.

4. The c Meta-Command

Generally, we have to change the energetic database and swap to a different one. The c meta-command permits us to connect with a brand new database. Let’s attempt it.AEsd1po.png

So, we’ve made chinook the energetic database. Now, we are able to write queries in opposition to the database. Let’s see how we are able to write a easy question in opposition to the actor desk within the chinook database.

yAImiDE.png

5. The d Meta-Command

To disclose the main points of every relation (desk, view, and so forth.), we are able to use the d relation-name meta-command.

For instance, d staff returns the desk’s columns and their knowledge sorts together with further data for every column, as proven under:HypcCxC.png

6. The dn Meta-Command

The dn meta-command permits us to record all of the schemas current in a PostgreSQL database. To see the output of this meta-command, let’s hook up with the Adventureworks database and record all the present schemas utilizing the dn meta-command.

rmIsk0e.png

7. The df Meta-Command

The df meta-command returns all of the obtainable capabilities of the present database. First, hook up with the Adventureworks database, sort df, and press Enter to see the way it works. It is going to present all of the capabilities current within the Adventureworks database.

tw9dN4J.png

8. The dv Meta-Command

The dv meta-command is one other helpful psql‘s backslash-command that permits us to record all of the views within the present database.

For instance, we are able to use this meta-command after connecting to the database to indicate the obtainable views within the chinook database.

vDTvd0g.png

NOTE

The psql consumer software has dozens of meta-commands, and discussing all of them is past this tutorial’s scope. In case you’re considering studying extra about these meta-commands, please discuss with PostgreSQl’s documentation portal.

Backup and Restore PostgreSQL Databases

Up to now, we’ve centered on utilizing the psql consumer software. However there are some further utilities bundled with PostgreSQL that make life simpler for database directors and knowledge engineers — particularly for these knowledge specialists who work on database upkeep duties.

9. The pg_dump Shopper Utility

The pg_dump consumer software generates a file with SQL instructions to make a backup of a database. If we run these SQL statements, we’ll recreate precisely the identical database with the identical content material.

The next assertion makes a textual content file containing all of the SQL statements required for recreating the mydb database.

% pg_dump mydb > dump_file.sql

10. Restoring Plain-Textual content Backups

Restoring a database from a plain-text file generated by the pg_dump consumer software is easy.

Many of the database specialists use the psql utility with the next choices to recreate a database that now we have a backup file of in plain-text format:

% createdb mydb_restored
% psql –host localhost –dbname mydb_restored –username postgres –file /Customers/mohammadmehdi/dump_file.sql
% psql –host localhost –port 5432 –dbname mydb_restored –username postgres

The three instructions above will create a brand new database known as mydb_restored, then the dump file will likely be restored into it, which can recreate all of the database’s objects that we already made a backup of it utilizing the pg_dump utility.

The final command connects to the mydb_restored database. So, we are able to record all the present relations on this database to make sure it’s precisely the precise copy of the mydb database.

ZEwHwUw.png

Abstract

This tutorial explored the PostgreSQL Shopper Functions by specializing in the psql utility and its meta-commands, making a database backup in a plain-text format utilizing pg_dump, then restoring it into a brand new database with psql.

This tutorial is simply an introduction to a few of the prospects of the PostgreSQL Shopper Functions. Now the doorways to discovering extra about these utilities are open to you, and one of the best reference is PostgreSQL Shopper Functions reference.

I hope that you’ve got realized one thing new as we speak. Be at liberty to attach with me on LinkedIn or Twitter.

Mehdi Lotfinejad

In regards to the writer

Mehdi Lotfinejad

Mehdi is a Senior Knowledge Engineer and Crew Lead at ADA. He’s knowledgeable coach who loves writing knowledge analytics tutorials.



Source link

Tags: CommandLinePostgreSQLUtilities
Next Post

Interested by ChatGPT: Exploring the origins of generative AI and pure language processing

Edith Elkind wins the 2023 ACM/SIGAI Autonomous Brokers Analysis Award

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent News

Modernización, un impulsor del cambio y la innovación en las empresas

March 21, 2023

How pure language processing transformers can present BERT-based sentiment classification on March Insanity

March 21, 2023

Google simply launched Bard, its reply to ChatGPT—and it needs you to make it higher

March 21, 2023

Automated Machine Studying with Python: A Comparability of Completely different Approaches

March 21, 2023

Why Blockchain Is The Lacking Piece To IoT Safety Puzzle

March 21, 2023

Dataquest : How Does ChatGPT Work?

March 21, 2023

Categories

  • A.I News
  • A.I. Startups
  • Computer Vision
  • Data science
  • Machine learning
  • Natural Language Processing
  • Robotics
A.I. Pulses

Get The Latest A.I. News on A.I.Pulses.com.
Machine learning, Computer Vision, A.I. Startups, Robotics News and more.

Categories

  • A.I News
  • A.I. Startups
  • Computer Vision
  • Data science
  • Machine learning
  • Natural Language Processing
  • Robotics
No Result
View All Result

Recent News

  • Modernización, un impulsor del cambio y la innovación en las empresas
  • How pure language processing transformers can present BERT-based sentiment classification on March Insanity
  • Google simply launched Bard, its reply to ChatGPT—and it needs you to make it higher
  • Home
  • DMCA
  • Disclaimer
  • Cookie Privacy Policy
  • Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2022 A.I. Pulses.
A.I. Pulses is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • A.I News
  • Computer Vision
  • Machine learning
  • A.I. Startups
  • Robotics
  • Data science
  • Natural Language Processing

Copyright © 2022 A.I. Pulses.
A.I. Pulses is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In