PostgreSQL procedural language "C" not found - postgresql

I am trying to use the PL/R procedural language in a PostgreSQL 9.2 database. I have installed the plr language and I am trying to add it to a database. When I run the command CREATE EXTENSION plr; I get the following error:
ERROR: language "C" does not exist
STATEMENT: CREATE EXTENSION plr;
ERROR: language "C" does not exist
When I list the available languages in the database with select * from pg_language; I get
lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | laninline | lanvalidator | lanacl
----------+----------+---------+--------------+---------------+-----------+--------------+--------
internal | 10 | f | f | 0 | 0 | 2246 |
c | 10 | f | f | 0 | 0 | 2247 |
sql | 10 | f | t | 0 | 0 | 2248 |
plpgsql | 10 | t | t | 12514 | 12515 | 12516 |
(4 rows)
So there is a language c but it is not in capital letters (not sure if that makes a difference).
I am wondering why the plr extension does not find the C procedural language?

You are probably running into this change in PostgreSQL 9.2 (quoting the release notes here):
No longer forcibly lowercase procedural language names in CREATE
FUNCTION (Robert Haas)
While unquoted language identifiers are still lowercased, strings and
quoted identifiers are no longer forcibly down-cased. Thus for example
CREATE FUNCTION ... LANGUAGE 'C' will no longer work; it must be
spelled 'c', or better omit the quotes.
It's also reflected in the manual for CREATE FUNCTION
lang_name
The name of the language that the function is implemented in. Can be SQL, C, internal, or the name of a user-defined procedural
language. For backward compatibility, the name can be enclosed by
single quotes.
Quoting the language name has been discouraged since at least version 7.3 (maybe longer), but old habits die hard, obviously. Removing the quotes around 'C' fixes the problem, arriving at: LANGUAGE c or LANGUAGE C.
PL/R wasn't ready for PostgreSQL 9.2 in that respect, judging from the project page.
Feedback from Joe Conway
Joe Conway left an answer that got deleted because it should be a comment. I paste it here for the general public who can't see deleted answers:
I got the message, just haven't had the time to do a new PL/R release.
Look for it by December, but in the meantime the manual workaround
noted above is pretty simple.

I had a similar issue with pg_collkey. I believe your situation may have the same solution. Here's what I did: There's a .sql file in your postgres extension directory that tells postgres how to install the extension. In my case, it's called pg_collkey--0.5.0.sql. You'll need to modify that sql file. On my system (using Mac OS X and Homebrew) the file is located at /usr/local/share/postgresql/extension/pg_collkey--0.5.0.sql). It probably contains a capital "C" in the LANGUAGE clause, like so:
CREATE OR REPLACE FUNCTION collkey (text, text, bool, int4, bool) RETURNS bytea
LANGUAGE 'C' IMMUTABLE STRICT AS
'$libdir/collkey_icu.so',
'pgsqlext_collkey';
Change it to a lower-case 'c' and re-run the "CREATE EXTENSION pg_collkey;" command in psql:
psql -c 'CREATE EXTENSION pg_collkey;' my_database_name
Of course, you'll need to use "plr" instead of pg_collkey for the extension name.

Related

PostgreSQL cannot generate uuid but uuid-ossp extension is installed?

postgresql11-server-11.8_2
When I try to add a new client in idempiere I get the following error message:
idempiere Version=7.1.0.202008290007
Initial Client Setup Process
Do you want to start the Process?
** org.postgresql.util.PSQLException: ERROR: function uuid_generate_v4() does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts. Where: PL/pgSQL function generate_uuid() line 3 at RETURN
This usually indicates that the uuid extension is missing from the database. But this is not the case.
[root#accounting-2 ~ (master)]# sudo -u postgres psql --dbname=idempiere
psql (11.8)
Type "help" for help.
idempiere=# \dx
List of installed extensions
Name | Version | Schema | Description
-----------+---------+------------+-------------------------------------------------
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
uuid-ossp | 1.1 | public | generate universally unique identifiers (UUIDs)
What is causing this? How is it fixed?
The output of \dx in my postgres looks like this:
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
uuid-ossp | 1.1 | adempiere | generate universally unique identifiers (UUIDs)
In your case it shows uuid-ossp installed in the public schema, while in my case is installed in adempiere schema.
Please try the following command in your idempiere database:
CREATE EXTENSION "uuid-ossp"

Getting ERROR: type "period" does not exist, even i have added btree_gist and temporal_tables extensions

I'm getting error even i have added btree_gist and temporal_tables extensions.
postgres=# \dx
Name | Version | Schema | Description
-----------------+---------+------------+-----------------------------------------------
btree_gist | 1.1 | public | support for indexing common datatypes in GiST
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
temporal_tables | 1.2.0 | public | temporal tables
(3 rows)
CREATE TABLE b (p PERIOD);
ERROR: type "period" does not exist
LINE 1: CREATE TABLE b (p PERIOD);
Version details
postgres=# select version();
version
---------------------------------------------------------------------------------------------
PostgreSQL 9.5.12 on x86_64-alpine-linux-musl, compiled by gcc (Alpine 5.3.0) 5.3.0, 64-bit
If you are talking about this extension, I am not surprised.
The extension does not define a data type or domain called period.

How to use extensions in Postgres installed with Homebrew on Mac OSX

I'd like to use the SPI extension in Postgres 10.2, which I installed with Homebrew. However,
CREATE EXTENSION spi;
fails with
ERROR: could not open extension control file "/usr/local/share/postgresql/extension/spi.control": No such file or directory
Looking inside that extension directory, I see many extensions, but not SPI. The Postgres documentation mentions that extensions would reside in a contrib directory of the distribution and that you can then build them individually, but I can't seem to find this directory anywhere. Any idea how I can obtain and install the SPI module?
https://www.postgresql.org/docs/current/static/contrib-spi.html
Each of the groups of functions described below is provided as a
separately-installable extension.
so you check and try:
t=# select * from pg_available_extensions where name in ('refint','timetravel','autoinc','insert_username','moddatetime');
name | default_version | installed_version | comment
-----------------+-----------------+-------------------+-------------------------------------------------------------
moddatetime | 1.0 | | functions for tracking last modification time
autoinc | 1.0 | | functions for autoincrementing fields
insert_username | 1.0 | | functions for tracking who changed a table
timetravel | 1.0 | | functions for implementing time travel
refint | 1.0 | | functions for implementing referential integrity (obsolete)
(5 rows)
t=# create extension refint ;
CREATE EXTENSION
t=# create extension timetravel;
CREATE EXTENSION
and so on...

to_tsvector in simple mode throwing away non english in some setups

On some pg installs I am noticing the following happens
sam=# select '你好 世界'::tsvector;
tsvector
---------------
'世界' '你好'
(1 row)
sam=# select to_tsvector('simple', '你好 世界');
to_tsvector
-------------
(1 row)
Even though my db is configured like so:
MBA:bin sam$ ./psql -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+-------------+-------------+-------------------
postgres | sam | UTF8 | en_AU.UTF-8 | en_AU.UTF-8 |
sam | sam | UTF8 | en_AU.UTF-8 | en_AU.UTF-8 |
template0 | sam | UTF8 | en_AU.UTF-8 | en_AU.UTF-8 | =c/sam +
| | | | | sam=CTc/sam
template1 | sam | UTF8 | en_AU.UTF-8 | en_AU.UTF-8 | =c/sam +
| | | | | sam=CTc/sam
(4 rows)
On other similar setups I am seeing select to_tsvector('simple', '你好 世界'); correctly return the tokens.
How do I diagnose the simple tokeniser to figure out why it is chucking out these letters?
Simplest repro seems to be installing postgres via postgres app. Does not happen when installing postgres on ubuntu with a locale set.
Unfortunately, default parser used by text search highly depends on the database initialization and especially on lc_collate and the current database object encoding.
This is due to some inner working of the default text parser. It is vaguely documented:
Note: The parser's notion of a "letter" is determined by the database's locale setting, specifically lc_ctype. Words containing only the basic ASCII letters are reported as a separate token type, since it is sometimes useful to distinguish them.
The important part is these comments in PostgreSQL source code:
/* [...]
* Notes:
* - with multibyte encoding and C-locale isw* function may fail
* or give wrong result.
* - multibyte encoding and C-locale often are used for
* Asian languages.
* - if locale is C then we use pgwstr instead of wstr.
*/
and below:
/*
* any non-ascii symbol with multibyte encoding with C-locale is
* an alpha character
*/
Consequently, if you want to use the default parser with Chinese, make sure your database is initialized with the C locale and you have a multibyte encoding, so all characters above U+007F will be treated as alpha (including spaces such as IDEOGRAPHIC SPACE U+3000 !). Typically, the following initdb call will do what you expect:
initdb --locale=C -E UTF-8
Otherwise, Chinese characters will be skipped and treated as blank.
You can check this with debug function ts_debug. With a database initialized with lc_collate=en_US.UTF-8 or any other configuration where tokenization fails, you will get:
SELECT * FROM ts_debug('simple', '你好 世界');
alias | description | token | dictionaries | dictionary | lexemes
-------+---------------+-----------+--------------+------------+---------
blank | Space symbols | 你好 世界 | {} | |
Conversely, with lc_collate=C and a UTF-8 database (initialized as above), you will get the proper result:
SELECT * FROM ts_debug('simple', '你好 世界');
alias | description | token | dictionaries | dictionary | lexemes
-------+-------------------+-------+--------------+------------+---------
word | Word, all letters | 你好 | {simple} | simple | {你好}
blank | Space symbols | | {} | |
word | Word, all letters | 世界 | {simple} | simple | {世界}
It seems, however, that you mean to tokenize Chinese text where words are already separated by regular spaces, i.e. tokenization/segmentation does not happen within PostgreSQL. For this use case, I strongly suggest using a custom parser. This is especially true if you do not use other features of PostgreSQL simple parser, such as tokenizing URLs.
A parser tokenizing on space characters is very easy to implement. In fact, in contrib/test_parser, there is a sample code doing exactly that. This parser will work whatever the locale. There was a buffer overrun bug in this parser that was fixed in 2012, make sure you use a recent version.

Could not access file "$libdir/plpgsql": No such file or directory

I'm at a loss, I'm having issues creating a stored proc in my local Postgres server (postgres.app, Mac OS X 10.7), as so
$ psql
psql (9.3.0)
Type "help" for help.
dchaston=# CREATE OR REPLACE FUNCTION table_update()
dchaston-# RETURNS TRIGGER AS $$
dchaston$# BEGIN
dchaston$# NEW.last_edit = now();
dchaston$# RETURN NEW;
dchaston$# END;
dchaston$# $$ language 'plpgsql';
ERROR: could not access file "$libdir/plpgsql": No such file or directory
I've checked the following:
Languages installed:
dchaston=# select * from pg_language;
lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | laninline | lanvalidator | lanacl
---------+----------+---------+--------------+---------------+-----------+--------------+--------
internal | 10 | f | f | 0 | 0 | 2246 |
c | 10 | f | f | 0 | 0 | 2247 |
sql | 10 | f | t | 0 | 0 | 2248 |
plpgsql | 10 | t | t | 12019 | 12020 | 12021 |
(4 rows)
lib directory (and pkglibdir just in case):
$ pg_config --libdir
/Applications/Postgres.app/Contents/MacOS/lib
$ pg_config --pkglibdir
/Applications/Postgres.app/Contents/MacOS/lib
File present:
$ cd /Applications/Postgres.app/Contents/MacOS/lib; ls plpg*
plpgsql.so
DLSUFFIX set correctly:
lib/pgxs/src/Makefile.shlib:135: DLSUFFIX = .so
Have tried uninstalling and reinstalling, but made no difference. Any ideas?
Did you install multiple instances (multiple versions or multiple instances of the same version) of Postgres on the same box? Standard Postgres is not fit for that. Debian or Ubuntu have additional infrastructure to allow multiple versions in parallel. I don't know about OS X, though.
In standard Postgres the path for $libdir is compiled into the program. Multiple versions do not get along.
When you execute pg_config --pkglibdir, make sure it's the one associated with your installation. Run:
which pg_config
Minor notes:
9.3.0? It's recommended to always upgrade to the latest point-release, which is 9.3.2 at the moment. Maybe a current source fixes your problem.
Also check your settings whether you are using the $libdir you think you are using:
SELECT * FROM pg_settings WHERE name ~~* '%lib%';
Don't quote the language name 'plpgsql' (though it's tolerated). It's an identifier: plpgsql.
Use the plpgsql assignment operator :=. = is undocumented but tolerated.
Since Postgres 9.4 both := and = are documented.
Otherwise your function definition is fine. That's not the root of the problem:
CREATE OR REPLACE FUNCTION table_update()
RETURNS trigger AS
$func$
BEGIN
NEW.last_edit := now();
RETURN NEW;
END
$func$ LANGUAGE plpgsql;
This one is related to the accepted answer.
I started getting the problem with libdir on MacOS Catalina 10.15.7 while doing the brew update as the brew update failed in between and I noticed that Postgresql was one of the many packages that it was trying to update and the above answer provided a good hint about multiple installations.
I verified that there weren't any additional versions of postgresql installed on my system. So a simple restart of the service did the trick for me:
brew services restart postgresql#10
I use FreeBSD and found a simple way to solve the problem, just copied the library from another server and pasted it into /usr/local/lib/postgresql/, which is the way $libdir. Although the versions of PostgreSQL are different, everything is working and I had no problems again.