-
-
Notifications
You must be signed in to change notification settings - Fork 40.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update all PostgreSQL roadmap content (#6241)
* update all postgresql roadmap content * added half the links * complete all link adding * Update src/data/roadmaps/postgresql-dba/content/[email protected]
- Loading branch information
Showing
167 changed files
with
659 additions
and
7,354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,8 @@ | ||
# Adding Extensions | ||
|
||
PostgreSQL provides various extensions to enhance its features and functionalities. Extensions are optional packages that can be loaded into your PostgreSQL database to provide additional functionality like new data types or functions. In this section, we will discuss how to add extensions in your PostgreSQL database. | ||
PostgreSQL provides various extensions to enhance its features and functionalities. Extensions are optional packages that can be loaded into your PostgreSQL database to provide additional functionality like new data types or functions. Using extensions can be a powerful way to add new features to your PostgreSQL database and customize your database's functionality according to your needs. | ||
|
||
## Pre-installed Extensions | ||
Learn more from the following resources: | ||
|
||
PostgreSQL comes with some pre-installed extensions that can be enabled easily. To see the list of available extensions, you can run the following SQL command: | ||
|
||
```sql | ||
SELECT * FROM pg_available_extensions; | ||
``` | ||
|
||
This command will display a table with columns: `name`, `default_version`, `installed_version`, `comment`. | ||
|
||
## Enabling an Extension | ||
|
||
To enable an extension, you can use the `CREATE EXTENSION` command followed by the extension name. For example, to enable the `hstore` extension, which is used to enable key-value pairs data storage, you can run the following command: | ||
|
||
```sql | ||
CREATE EXTENSION hstore; | ||
``` | ||
|
||
If you want to enable a specific version of the extension, you can use the `VERSION` keyword followed by the desired version: | ||
|
||
```sql | ||
CREATE EXTENSION hstore VERSION '1.4'; | ||
``` | ||
|
||
Remember that you might need to have the necessary privileges to create an extension. For example, you might need to be a superuser or have the `CREATEROLE` privilege. | ||
|
||
## Updating an Extension | ||
|
||
You can update an installed extension to a new version using the `ALTER EXTENSION` command. For example, to update the `hstore` extension to version '1.5', you can run the following command: | ||
|
||
```sql | ||
ALTER EXTENSION hstore UPDATE TO '1.5'; | ||
``` | ||
|
||
## Install Custom Extensions | ||
|
||
You can also add custom extensions to your PostgreSQL instance. You can generally find the source code and installation instructions for custom extensions on GitHub or other open-source platforms. Custom extensions may require additional steps such as compiling the source code or updating `pg_config` during the installation process. | ||
|
||
## Removing an Extension | ||
|
||
If you no longer need an extension, you can remove it using the `DROP EXTENSION` command. For example, to remove the `hstore` extension, you can run the following command: | ||
|
||
```sql | ||
DROP EXTENSION hstore; | ||
``` | ||
|
||
_Remember that removing an extension might lead to loss of data or functionality that was dependent on the extension._ | ||
|
||
In this section, we covered how to add, enable, update, and remove PostgreSQL extensions. Using extensions can be a powerful way to add new features to your PostgreSQL database and customize your database's functionality according to your needs. | ||
- [@official@PostgreSQL extensions](https://www.postgresql.org/download/products/6-postgresql-extensions/) | ||
- [@official@Create Extension](https://www.postgresql.org/docs/current/sql-createextension.html) |
52 changes: 1 addition & 51 deletions
52
src/data/roadmaps/postgresql-dba/content/advanced-topics@09QX_zjCUajxUqcNZKy0x.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,3 @@ | ||
# Advanced Topics in PostgreSQL Security | ||
|
||
In addition to basic PostgreSQL security concepts, such as user authentication, privilege management, and encryption, there are several advanced topics that you should be aware of to enhance the security of your PostgreSQL databases. This section will discuss these advanced topics and provide a brief overview of their significance. | ||
|
||
## Row Level Security (RLS) | ||
|
||
Row Level Security (RLS) in PostgreSQL allows you to define security policies on a per-row basis. This means that you can control which rows of a table can be accessed by which users based on specific conditions. By implementing RLS, you can ensure that users only have access to relevant data, which promotes data privacy and security. | ||
|
||
**Example:** | ||
|
||
```sql | ||
CREATE POLICY user_data_policy | ||
ON users | ||
FOR SELECT | ||
USING (current_user = user_name); | ||
ALTER TABLE users FORCE ROW LEVEL SECURITY; | ||
``` | ||
|
||
## Security-Enhanced PostgreSQL (SE-PostgreSQL) | ||
|
||
Security-Enhanced PostgreSQL (SE-PostgreSQL) is an extension of PostgreSQL that integrates SELinux (Security-Enhanced Linux) security features into the PostgreSQL database system. This ensures that strict mandatory access control policies are applied at both the operating system and database levels, providing additional security and protection against potential attacks. | ||
|
||
## Auditing | ||
|
||
Auditing is a crucial aspect of database security, as it helps you monitor user activity and detect any unauthorized access or suspicious behavior. PostgreSQL offers various extensions for auditing, such as `pgAudit`, which provides detailed logs of user operations, including statement types and parameters. | ||
|
||
**Example:** | ||
|
||
```sql | ||
shared_preload_libraries = 'pgaudit' | ||
pgaudit.log = 'DDL, ROLE, FUNCTION' | ||
``` | ||
|
||
## Connection Pooling and SSL Certificates | ||
|
||
Connection pooling improves the efficiency of your PostgreSQL connections by reusing existing connections rather than creating new ones every time. This can greatly reduce the overhead of establishing secure connections. One popular connection pooler is `pgBouncer`, which also supports SSL for enhanced security. | ||
|
||
To further improve connection security, you can use SSL certificates to authenticate client-server connections, ensuring that data is encrypted in transit and reducing the risk of man-in-the-middle attacks. | ||
|
||
## Backup Encryption | ||
|
||
Your PostgreSQL database backups should also be secured, as they contain sensitive data that can be exploited if they fall into the wrong hands. You can encrypt your backups using tools such as `pgBackRest`, which offers strong encryption algorithms like AES-256 to protect your backup data. | ||
|
||
**Example:** | ||
|
||
```ini | ||
[global] | ||
repo1-path=/var/lib/pgbackrest | ||
repo1-cipher-type=aes-256-cbc | ||
repo1-cipher-pass=backup_passphrase | ||
``` | ||
|
||
By understanding and implementing these advanced security topics in your PostgreSQL environment, you can ensure that your databases remain secure and protected from potential threats. Make sure to keep your PostgreSQL software up-to-date and regularly apply security patches to maintain a strong security posture. | ||
In addition to basic PostgreSQL security concepts, such as user authentication, privilege management, and encryption, there are several advanced topics that you should be aware of to enhance the security of your PostgreSQL databases. |
47 changes: 4 additions & 43 deletions
47
.../postgresql-dba/content/aggregate-and-window-functions@iQqEC1CnVAoM7x455jO_S.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,8 @@ | ||
# Aggregate and Window Functions | ||
|
||
In this section, we'll dive deep into aggregate and window functions, which are powerful tools in constructing advanced SQL queries. These functions help you to perform operations on a set of rows and return one or multiple condensed results. | ||
Aggregate functions in PostgreSQL perform calculations on a set of rows and return a single value, such as `SUM()`, `AVG()`, `COUNT()`, `MAX()`, and `MIN()`. Window functions, on the other hand, calculate values across a set of table rows related to the current row while preserving the row structure. Common window functions include `ROW_NUMBER()`, `RANK()`, `DENSE_RANK()`, `NTILE()`, `LAG()`, and `LEAD()`. These functions are crucial for data analysis, enabling complex queries and insights by summarizing and comparing data effectively. | ||
|
||
## Aggregate Functions | ||
Learn more from the following resources: | ||
|
||
Aggregate functions are used to perform operations on a group of rows, like calculating the sum, average, or count of the rows, and returning a single result. Common aggregate functions include: | ||
|
||
- `SUM`: Calculates the total sum of the values in the column | ||
- `AVG`: Calculates the average of the values in the column | ||
- `MIN`: Finds the minimum value in the column | ||
- `MAX`: Finds the maximum value in the column | ||
- `COUNT`: Counts the number of rows (or non-null values) in the column | ||
|
||
Aggregate functions are commonly used with the `GROUP BY` clause to group rows by one or more columns. Here's an example that calculates the total sales per product: | ||
|
||
```sql | ||
SELECT product_id, SUM(sales) AS total_sales | ||
FROM sales_data | ||
GROUP BY product_id; | ||
``` | ||
|
||
## Window Functions | ||
|
||
Window functions are similar to aggregate functions in that they operate on a group of rows. However, instead of returning a single result for each group, window functions return a result for each row, based on its "window" of related rows. | ||
|
||
Window functions are usually used with the `OVER()` clause to define the window for each row. The window can be defined by `PARTITION BY` and `ORDER BY` clauses within the `OVER()` clause. | ||
|
||
Window functions can be used with the following types of functions: | ||
|
||
- Aggregate functions (e.g., `SUM`, `AVG`, `MIN`, `MAX`, `COUNT`) | ||
- Ranking functions (e.g., `RANK`, `DENSE_RANK`, `ROW_NUMBER`) | ||
- Value functions (e.g., `FIRST_VALUE`, `LAST_VALUE`, `LAG`, `LEAD`) | ||
|
||
Here's an example that calculates the cumulative sum of sales per product, ordered by sale date: | ||
|
||
```sql | ||
SELECT product_id, sale_date, sales, | ||
SUM(sales) OVER (PARTITION BY product_id ORDER BY sale_date) AS cumulative_sales | ||
FROM sales_data; | ||
``` | ||
|
||
In this example, the `SUM(sales)` aggregate function is used with the `OVER()` clause to create a window for each row, partitioned by `product_id` and ordered by `sale_date`. This allows you to calculate the cumulative sum of sales for each product up to the current row. | ||
|
||
## Conclusion | ||
|
||
Understanding and using aggregate and window functions is essential to perform advanced data analysis with SQL. By mastering the use of these functions, you can create complex SQL queries to efficiently analyze your data and make better-informed decisions. So, keep practicing and exploring different combinations of functions and window definitions to sharpen your skills! | ||
- [@article@Data Processing With PostgreSQL Window Functions](https://www.timescale.com/learn/postgresql-window-functions) | ||
- [@article@Why & How to Use Window Functions to Aggregate Data in Postgres](https://coderpad.io/blog/development/window-functions-aggregate-data-postgres/) |
90 changes: 5 additions & 85 deletions
90
src/data/roadmaps/postgresql-dba/content/ansible@RqSfBR_RuvHrwHfPn1jwZ.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,9 @@ | ||
# Ansible for PostgreSQL Configuration Management | ||
|
||
Ansible is a widely used open-source configuration management and provisioning tool that helps automate many tasks for managing servers, databases, and applications. It uses a simple, human-readable language called YAML to define automation scripts, known as "playbooks." In this section, we'll explore how Ansible can help manage PostgreSQL configurations. | ||
Ansible is a widely used open-source configuration management and provisioning tool that helps automate many tasks for managing servers, databases, and applications. It uses a simple, human-readable language called YAML to define automation scripts, known as “playbooks”. By using Ansible playbooks and PostgreSQL modules, you can automate repetitive tasks, ensure consistent configurations, and reduce human error. | ||
|
||
## Key Features of Ansible | ||
Learn more from the following resources: | ||
|
||
- Agentless: Ansible does not require installing any agents or software on the servers being managed, making it easy to set up and maintain. | ||
- Playbooks: Playbooks are the core component of Ansible, and they define automation tasks using YAML. They are simple to understand and write. | ||
- Modules: Ansible modules are reusable components that perform specific actions, such as installing packages, creating databases, or managing services. There are numerous built-in modules for managing PostgreSQL. | ||
- Idempotent: Ansible ensures that playbook runs have the same effect, regardless of how many times they are executed. This ensures consistent server and application configuration. | ||
- Inventory: Ansible uses an inventory to track and manage hosts. It is a flexible system that can group and organize servers based on their characteristics or functions. | ||
|
||
## Using Ansible with PostgreSQL | ||
|
||
- **Install Ansible**: First, you'll need to install Ansible on your control machine (the machine where you'll execute playbooks from), using your package manager or following the official [installation guide](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html). | ||
|
||
- **Create a playbook**: Create a new playbook file (e.g., `postgres_setup.yml`) to define the automation tasks for PostgreSQL. In this file, you'll write YAML instructions to perform tasks like installation, configuration, and database setup. | ||
|
||
- **Use the PostgreSQL modules**: Ansible has built-in support for PostgreSQL through several modules, such as `postgresql_db`, `postgresql_user`, and `postgresql_privs`. Use these modules in your playbooks to manage your PostgreSQL server and databases. | ||
|
||
- **Apply the playbook**: Once you have created the playbook, you can apply it with the `ansible-playbook` command, specifying the inventory file and the target hosts. | ||
|
||
Example playbook for installing PostgreSQL on Ubuntu: | ||
|
||
```yaml | ||
--- | ||
- name: Install PostgreSQL | ||
hosts: all | ||
become: yes | ||
tasks: | ||
- name: Update apt cache | ||
apt: update_cache=yes cache_valid_time=3600 | ||
|
||
- name: Install required packages | ||
apt: name={{ item }} state=present | ||
loop: | ||
- python3-psycopg2 | ||
- postgresql | ||
- postgresql-contrib | ||
|
||
- name: Configure PostgreSQL | ||
block: | ||
- name: Add custom configuration | ||
template: | ||
src: templates/pg_hba.conf.j2 | ||
dest: /etc/postgresql/{{ postgres_version }}/main/pg_hba.conf | ||
notify: Restart PostgreSQL | ||
|
||
- name: Reload configuration | ||
systemd: name=postgresql state=reloaded | ||
handlers: | ||
- name: Restart PostgreSQL | ||
systemd: name=postgresql state=restarted | ||
``` | ||
In this example, the playbook installs the required packages, configures PostgreSQL using a custom `pg_hba.conf` file (from a Jinja2 template), and then reloads and restarts the PostgreSQL service. | ||
|
||
## pgLift for Ansible | ||
|
||
pgLift is a PostgreSQL automation tool that helps you manage your PostgreSQL servers and databases. It includes a set of Ansible modules that can be used to automate common tasks, such as creating databases, users, and extensions, or managing replication and backups. | ||
|
||
pgLift modules are available on [Ansible Galaxy](https://galaxy.ansible.com/pglift), and can be installed using the `ansible-galaxy` command: | ||
|
||
```bash | ||
ansible-galaxy collection install pglift.pglift | ||
``` | ||
|
||
Once installed, you can use the modules in your playbooks: | ||
|
||
```yaml | ||
--- | ||
- name: Create a database | ||
hosts: all | ||
become: yes | ||
tasks: | ||
- name: Create a database | ||
pglift.pglift.postgresql_db: | ||
name: mydb | ||
owner: myuser | ||
encoding: UTF8 | ||
lc_collate: en_US.UTF-8 | ||
lc_ctype: en_US.UTF-8 | ||
template: template0 | ||
state: present | ||
``` | ||
|
||
## Conclusion | ||
|
||
Ansible is a powerful configuration management tool that can greatly simplify the maintenance and deployment of PostgreSQL servers. By using Ansible playbooks and PostgreSQL modules, you can automate repetitive tasks, ensure consistent configurations, and reduce human error. | ||
- [@official@Ansible Website](https://www.ansible.com/) | ||
- [@opensource@ansible/ansible](https://github.com/ansible/ansible) | ||
- [@article@Ansible Tutorial for Beginners: Ultimate Playbook & Examples](https://spacelift.io/blog/ansible-tutorial) |
43 changes: 3 additions & 40 deletions
43
...admaps/postgresql-dba/content/any-programming-language@j5YeixkCKRv0sfq_gFVr9.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,7 @@ | ||
# Programming Languages and PostgreSQL Automation | ||
|
||
In this section, we will discuss different programming languages that can be used to automate tasks and manipulate data in PostgreSQL databases. | ||
PostgreSQL supports various languages for providing server-side scripting and developing custom functions, triggers, and stored procedures. When choosing a language, consider factors such as the complexity of the task, the need for a database connection, and the trade-off between learning a new language and leveraging existing skills. | ||
|
||
PostgreSQL supports various languages for providing server-side scripting and developing custom functions, triggers, and stored procedures. Here, we will introduce some popular programming languages and tools that can be used for interacting with PostgreSQL. | ||
Learn more from the following resources: | ||
|
||
## PL/pgSQL | ||
|
||
PL/pgSQL is a procedural language designed specifically for PostgreSQL. It is an open-source extension to SQL that allows you.Performing complex operations on the server-side should be done with PL/pgSQL language without the requirement for round-trip between your application and the database server which can help increase performance. | ||
|
||
Some benefits of using PL/pgSQL are: | ||
|
||
- Easy to learn, especially for users familiar with SQL | ||
- Close integration with PostgreSQL, providing better performance and lower overhead | ||
- Support for local variables, conditional expressions, loops, and error handling | ||
|
||
## PL/Tcl, PL/Perl, and other PL languages | ||
|
||
PostgreSQL also supports other procedural languages such as PL/Tcl and PL/Perl. These are scripting languages that run inside the PostgreSQL engine and provide more flexibility than SQL. They are useful for tasks that require complex string manipulation, file I/O, or interaction with the operating system. | ||
|
||
While less common, PostgreSQL supports other scripting languages like PL/Python, PL/R, and PL/Java. | ||
|
||
## SQL | ||
|
||
SQL is, of course, the most basic and widely used language for interacting with PostgreSQL databases. While not a general-purpose programming language, SQL is useful for automating simple tasks and manipulating data directly in the database. | ||
|
||
Consider these points when using SQL for PostgreSQL automation: | ||
|
||
- SQL scripts can be easily scheduled and run by cron jobs or through an application | ||
- SQL is the most efficient way to perform CRUD (Create, Read, Update, Delete) operations on the database | ||
- For more complex tasks, it's often better to use a higher-level programming language and library | ||
|
||
## Application-Level Languages | ||
|
||
You can use higher-level programming languages like Python, Ruby, Java, and JavaScript (with Node.js) to automate tasks and manipulate data in your PostgreSQL databases. These languages have libraries and frameworks to connect and interact with PostgreSQL databases easily: | ||
|
||
- Python: psycopg2 or SQLAlchemy | ||
- Ruby: pg or ActiveRecord (for Ruby on Rails) | ||
- Java: JDBC or Hibernate | ||
- JavaScript: pg-promise or Sequelize (for Node.js) | ||
|
||
These languages and libraries provide a more feature-rich and expressive way to interact with your PostgreSQL databases. They also enable you to build more sophisticated automation and use programming constructs like loops, conditionals, and error handling that are not easily accomplished with pure SQL. | ||
|
||
In conclusion, there are multiple programming languages available for PostgreSQL automation, each with its advantages and use cases. When choosing a language, consider factors such as the complexity of the task, the need for a database connection, and the trade-off between learning a new language and leveraging existing skills. | ||
- [@official@Procedural Languages](https://www.postgresql.org/docs/current/external-pl.html) |
Oops, something went wrong.