跳转到主要内容
Chinese, Simplified

category

在这篇文章中,我们将逐步讨论如何在Windows机器上安装PostgreSQL和ApacheAGE。在本指南结束时,您将拥有一个功能齐全的PostgreSQL数据库和ApacheAGE图形数据库,可以用于数据驱动的应用程序。

什么是PostgreSQL?

PostgreSQL是世界上最著名的关系数据库之一,旨在管理和存储大量结构化数据。

PostgreSQL是开源的,以其可靠性、健壮性和可扩展性而闻名。它提供了各种高级功能,包括对事务、存储过程和触发器的支持。

PostgreSQL支持广泛的数据类型,包括文本、数字和日期/时间数据,以及更复杂的数据结构,如数组、JSON和XML。

什么是Apache AGE?

ApacheAGE是一个建立在PostgreSQL之上的图形数据库系统。它允许用户以高性能和可扩展的方式存储、管理和分析大规模图形数据。

ApacheAGE将强大的关系数据库管理系统(PostgreSQL)的优势与图形数据库的灵活性和可扩展性相结合。这意味着用户可以以关系格式存储数据,还可以对数据执行基于图的查询和分析。

如何安装PostgreSQL和Apache Age?

目前,Apache AGE不支持Windows。因此,在本教程中,我们将使用Windows Subsystem for Linux(WSL)作为替代方案。

1. Install WSL.


To enable WSL on your computer, follow these steps: First, go to the Control Panel, and then select Programs. Next, select Turn Windows features on or off. From the list of features, enable both Virtual Machine Platform and Windows Subsystem for Linux, as shown in the image

Image description

After enabling WSL, the next step is to install a Linux distribution for Windows. To do this, open the Microsoft Store and search for 'Linux.' You will see several options available, and you can choose the one you prefer. For the purposes of this tutorial, we will be using 'Ubuntu 22.04.2 LTS'.

2. Installing PostgreSQL from source code.


Please note that currently, Apache AGE only supports PostgreSQL versions 11 and 12, so we must install one of these versions. Before proceeding, we need to install some dependencies. To do this, open a bash terminal by navigating to any directory and typing 'bash' in the address bar, and then run the appropriate command.

sudo apt install git libreadline-dev zlib1g-dev bison flex build-essential

Next, create a directory where you want to install PostgreSQL and clone the Postgres repository into it.

mkdir postgres-AGE-project
cd postgres-AGE-project
git clone https://git.postgresql.org/git/postgresql.git

Navigate to the 'postgresql' directory and switch to a compatible version branch. For the purposes of this tutorial, we'll be using version 12.

cd postgresql
git checkout REL_12_STABLE

Compile the source code and specify the directory where you want the binaries to be installed. Note that this process may take some time to complete.

./configure –prefix=/usr/local/pgsql-12
make 

After the compilation process is complete, run the following command to add permissions for the binaries directory and replace user by your username. Once this is done, proceed to install PostgreSQL

sudo mkdir /usr/local/pgsql-12
sudo chown user /usr/local/pgsql-12
make install

To ensure that PostgreSQL can be accessed from anywhere in the terminal, it is necessary to set up the following environment variables
These commands will add the PostgreSQL binaries directory to the system path and set the PGDATA directory to the location of the PostgreSQL data files.

export PATH=/usr/local/pgsql-12/bin/:$PATH
export PGDATA=/usr/local/pgsql-12/bin/data

Now that you have installed PostgreSQL, you can create a new cluster, which is a collection of databases managed by a single instance of the PostgreSQL server. To create a new cluster, run the following command:

initdb

After initializing the cluster, you can start the PostgreSQL server by running the following command:

pg_ctl -D /usr/local/pgsql-12/bin/data -l logfile start

Now you can start PostgreSQL by running the following command:

psql postgres

Congratulations! You have successfully installed and started PostgreSQL.

To exit PostgreSQL run \q

To stop the server run the following command:

pg_ctl -D /usr/local/pgsql-12/bin/data -l logfile stop

If you would like more detailed information about the installation process, you can visit the following link: PostgreSQL documentation

3. Installing Apache AGE from source code.


To install Apache AGE from source code, go to the main directory of the postgres-AGE-project that we created earlier and execute the following command to clone the AGE project.

git clone https://github.com/apache/age.git

To proceed with the installation, navigate to the project directory and switch to the latest stable release, which is version 1.1.0.

cd age
git checkout release/PG12/1.1.0

Set the environment variable PG_CONFIG. we need to set the PG_CONFIG environment variable to specify the location of the PostgreSQL pg_config utility. pg_config is a command-line utility that provides information about the installed version of PostgreSQL, including the location of files and libraries required for compiling and linking programs against PostgreSQL. Apache AGE uses pg_config to determine the location of the PostgreSQL header files and libraries needed to compile the AGE extension.

export PG_CONFIG=/usr/local/pgsql-12/bin/pg_config

Then install AGE extension by running this command:

make install

Now you have AGE installed to add the extension in your postgres server run the following SQL commands:

CREATE EXTENSION age;    

Then every time you want to use AGE you must load the extension.

LOAD 'age';    

Great job! You have successfully installed Apache AGE on your system.

You can find further information on AGE installation and usage on the official Apache AGE documentation at AGE documentation.

References
PostgreSQL
AGE - Installation giude

Contribute to Apache AGE
Apache AGE website: https://age.apache.org/
Apache AGE Github: https://github.com/apache/age

原文地址
https://dev.to/omarsaad/step-by-step-guide-to-install-postgresql-apache-age-on-windows-28gf
本文地址
Article

微信

知识星球

微信公众号

视频号