Found 26 Articles for PostgreSQL

How to add column to an existing table in PostgreSQL?

Yash Sanghvi
Updated on 02-Feb-2021 12:07:55

785 Views

The syntax to add a new column to an existing table is quite straightforward.ALTER TABLE table_name ADD COLUMN column_name column_type column_constraint;Say you have existing table marks. An example is given below −serial_nonameroll_nomarks_obtainedperc_marksmax_marksdate_of_entry1Yash2642421002021-01-302Isha5617587.52002021-01-30Now, suppose you want to add a column named subject. You can do that using −ALTER TABLE marks ADD COLUMN subject VARCHAR;Now if you query the table again using, SELECT * from marksYou will see the following output  −serial_nonameroll_nomarks_obtainedperc_ marksmax_ marksdate_ of_ entrysubject1Yash2642421002021-01-30[null]2Isha5617587.52002021-01-30[null]Note that the values in the subject column are null because we have just created the column, not populated it. We can populate it using the UPDATE ... Read More

How to create a table in PostgreSQL?

Yash Sanghvi
Updated on 02-Feb-2021 11:45:34

204 Views

Creating a table in PostgreSQL is pretty straightforward. The syntax is −CREATE TABLE table_name(    Column1_name type optional_constraint,    Column2_name type optional_constraint,    .    .    .    ColumnN_name type optional constraint );If you want to make sure that your table is created only if it doesn’t already exist, you can specify that explicitly −CREATE TABLE IF NOT EXISTS table_name(…);An example of table creation is given below −CREATE TABLE marks(    serial_no SERIAL PRIMARY KEY,    name VARCHAR,    roll_no INTEGER,    marks_obtained INTEGER,    perc_marks DOUBLE PRECISION,    max_marks INTEGER,    date_of_entry DATE );The above command will just ... Read More

How to Kill queries in pgAdmin in PostgreSQL?

Yash Sanghvi
Updated on 02-Feb-2021 11:41:24

4K+ Views

Sometimes, some rogue queries can take too long to execute. If the queries are blocking in nature, i.e., they restrict access to a table while they are executing, then any other query on the same table will be put on hold, and this leads to a pile-up of queries. This can, depending on your DB load, even cause the max connections to be exceeded. Luckily, you can easily kill long queries in pgAdmin.Go to Dashboard in your pgAdmin. At the bottom, in the Server Activity section, under the Sessions Tab, you can see all the Active queries.Now, notice the cross ... Read More

How to Query a DB in pgAdmin in PostgreSQL?

Yash Sanghvi
Updated on 02-Feb-2021 11:41:01

3K+ Views

Querying a DB in pgAdmin is quite straightforward. Locate your DB in the Servers dropdown on the left, and extend its dropdown, till you see the Schemas dropdown.Once you click on Schemas, the black button on the top, with the DB symbol and the play arrow will become clickable.Click on that button, and you will see a Query Tab open up. That’s it, you can type your queries for this particular DB in that box, and click the play arrow button to execute the queries.The output will be seen on the bottom, in the ‘Data Output’ section.Read More

How To Change PostgreSQL Data Folder Location on Ubuntu 16.04

karthikeya Boyini
Updated on 21-Jan-2020 08:00:43

2K+ Views

In this article, we will learn how to change or relocate the PostgreSQL Database data directory to the new location on Ubuntu 16.04. This database grows more frequently and depends upon the size of the company, as we needed more space and for security reasons we will change the data directory to the other volume or other location.PrerequisitesAn Ubuntu machine with a non-root user with Sudo permission.A PostgreSQL server installed and working.A new volume or location where we want to move the database data location, the new location will be /mnt/data_vol/PostgreSQL as the data_vol is the new volume attached to ... Read More

How to connect to PostgreSQL database using a JDBC program?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

685 Views

PostgreSQL is an open source relational database management system (DBMS) developed by a worldwide team of volunteers. PostgreSQL is not controlled by any corporation or other private entity and the source code is available free of charge.PostgreSQL runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It supports text, images, sounds, and video, and includes programming interfaces for C / C++, Java, Perl, Python, Ruby, Tcl and Open Database Connectivity (ODBC).Download the latest version of postgresql- from postgresql-jdbc repository.Add downloaded jar file postgresql-(VERSION).jdbc.jar in your class path.ExampleFollowing JDBC program ... Read More

Advertisements