Translate

Sunday 26 November 2023

how to create database in postgresql in pgadmin an psql 05

 how to create database in postgresql in pgadmin an psql



Creating a database in PostgreSQL using pgAdmin involves defining the database's properties and establishing its connection to the PostgreSQL server. Here's a step-by-step guide on how to create a database in PostgreSQL using pgAdmin:

Prerequisites:

  1. A running PostgreSQL server with pgAdmin installed and configured.

  2. Access to pgAdmin with administrative privileges.

Steps:

  1. Launch pgAdmin and connect to the PostgreSQL server.

  2. Expand the "Servers" node in the Object Browser pane.

  3. Right-click the server name and select "Create > Database".

  4. In the "Create - Database" dialog box, enter the desired name for the database in the "Name" field.

  5. Optionally, specify the encoding for the database in the "Encoding" dropdown menu. The default encoding is UTF8, which is a widely supported Unicode encoding.

  6. Optionally, select a template database to use as the basis for the new database in the "Template" dropdown menu. Template databases contain pre-defined schemas and objects that can be used as a starting point for your new database. If you are unsure which template to use, the default template is usually a good choice.

  7. Click "Create" to create the database. The new database will be created and will appear in the Object Browser pane under the "Databases" node.

Additional Notes:

  • You can also create a database using the SQL command CREATE DATABASE. However, using pgAdmin provides a graphical user interface that is often easier to use, especially for those who are not familiar with SQL syntax.

  • Once you have created a database, you can start creating tables, views, and other database objects within it. To create a table, right-click the database name in the Object Browser pane and select "Create > Table". To create a view, right-click the database name in the Object Browser pane and select "Create > View".



CREATE DATABASE vlrtraining  WITH  OWNER = venkat  ENCODING = 'UTF8'  LOCALE_PROVIDER = 'libc'  CONNECTION LIMIT = -1  IS_TEMPLATE = False;



Here's a breakdown of the statement:


SQL

CREATE DATABASE vlrtraining

This part creates a new database named vlrtraining.


SQL

WITH OWNER = venkat

This part specifies that the owner of the new database should be the user venkat. The owner has full control over the database and can manage its objects and privileges.


SQL

ENCODING = 'UTF8'

This part sets the encoding for the database to UTF8. UTF8 is a widely supported Unicode encoding that allows for storing and manipulating characters from various languages.


SQL

LOCALE_PROVIDER = 'libc'

This part specifies the locale provider for the database. The locale provider determines how the database sorts and formats data according to different locales or regions.


SQL

CONNECTION LIMIT = -1

This part sets the connection limit for the database to -1. This means that there is no limit on the number of concurrent connections that can be made to the database.


SQL

IS_TEMPLATE = False;

This part specifies that the database is not a template database. Template databases are used as blueprints for creating new databases. Setting IS_TEMPLATE = False indicates that this database is not intended to be used as a template.

In summary, this SQL statement creates a new database named vlrtraining with specific ownership, encoding, locale settings, connection limits, and template status.