473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Storing Configuration settings for a database?

I want to store config file keys and values in my PG database
in order to 1) be able to INSERT/UPDATE/DELETE configuration settings
without a flat file and 2) give access to the config settings with
my web application.

Right now, my java application uses a config file similar to an .INI
file with the following format:

[section1]
key1 = value1
key2 = "Value Two"
multi word key3 = 12345
[section2]
...

My question is ... can this be done in PG, should it be done, and what's
the best way to store the data? I can flatten the tree heirarchy if
necessary to yeild something like:

section1.key1 = value1
section1.key2 = "Value Two"
section1.multi word key3 = 12345
...

Since PG stores different datatypes it'd be ideal to have integers be
ints and strings as varchar etc, but to do this means I'd have to define
a separate column for each config option and I'd end up with only one
row of data.

If I use two columns instead like KEY / VALUE, then all values must be of
the same datatype (probably VARCHAR) and setting or reading values will
require casts and parsing of data constantly by applications using the
configs.

Who has built something similar to what I'm attempting, and what do you
recommend?

Dante

----------
D. Dante Lorenso
da***@lorenso.com

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05 #1
3 1728
On Monday 26 January 2004 11:47, D. Dante Lorenso wrote:
I want to store config file keys and values in my PG database
in order to 1) be able to INSERT/UPDATE/DELETE configuration settings
without a flat file and 2) give access to the config settings with
my web application.

Right now, my java application uses a config file similar to an .INI
file with the following format:

[section1]
key1 = value1
key2 = "Value Two"
multi word key3 = 12345
[section2] Who has built something similar to what I'm attempting, and what do you
recommend?


I tend to have something like:

CREATE TABLE config_settings AS (
section varchar(64),
item varchar(64),
type varchar(16),
value text,
PRIMARY KEY (section,item)
);

In general, two levels (section,item) seem enough, but it's trivial to add
another. I cast the value from text => my desired type in the app (or raise
an exception if there is a problem).

Oh - I frequently add a "notes" or "description" column to for instructions on
what value should go in.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 22 '05 #2
On Jan 26, 2004, at 6:47 AM, D. Dante Lorenso wrote:
<snip>
If I use two columns instead like KEY / VALUE, then all values must be
of
the same datatype (probably VARCHAR) and setting or reading values will
require casts and parsing of data constantly by applications using the
configs.

Who has built something similar to what I'm attempting, and what do you
recommend?


heh, I'd say use XML (and Castor to autogenerate objects for your
configuration schema), but since you're talking about postgres...

Using the JDBC drivers (dunno about the other interfaces), you can
actually call ResultSet.getInt(), .getLong(), .getFloat(). getXXX() on
a column that is defined as a character field (varchar, text).

CREATE TABLE settings (
section varchar(8),
key varchar(255),
value text
);
INSERT INTO settings values ('sec1', 'mykey', '42');

Then just do this:

Statement stmt = _conn.createStatement();
ResultSet rs = stmt.executeQuery("select value from settings where
section='sec1' and key='mykey'");
rs.next();
int value = rs.getInt("value");
stmt.close();

In reality, I don't know if this is a good idea or not as I suppose
you're relying on an implementation detail of the JDBC drivers, but it
works.

One of the nice side benefits of this is that if you call .getInt() for
a value of, say, "beer", you'll get a nice
java.lang.NumberFormatException, so it'll be rather easy to trap and
workaround misconfigurations.

eric
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #3
> I want to store config file keys and values in my PG database
in order to 1) be able to INSERT/UPDATE/DELETE configuration settings
without a flat file and 2) give access to the config settings with
my web application.

In GnuMed (www.gnumed.org) we do it like this:

http://savannah.gnu.org/cgi-bin/view...n.sql?rev=1.28

(look at the cfg_* tables)

Regards,

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: serge calderara | last post by:
dear all, I have problem accessing section group in my configuration application file. I got an error saying thta I can have only one section ???? here is my application configuration looks...
4
by: Oliver Stratmann | last post by:
Hello All, does anyone know, where the configuration of a db2-client on a windows-machine is stored? I searched the registry and the filesystem on my machine and couldn't find anything. Is...
3
by: Florida Coder | last post by:
I have the need to store some application specific configuration data to be used by a class library and or a windows service. I would like to do this in a fashion similar to the way we do with...
4
by: craig | last post by:
Some of the user interface components I am using (Infragistics) are capable of generating both XML and binary data that represents component configuration settings as defined by the user. I would...
7
by: MrNobody | last post by:
I was a Java developer so I'm used to using property files as a means to keep configuration settings for my apps. I'm wondering what options are there with ..NET? Some settings I want to include...
4
by: Andy | last post by:
Is it possible to use a Settings / Configuration file in VS 2005 / .Net 2.0 in a dll? Or is this feature limited to an executable? We have some .dlls where a configuration file would be helpful...
9
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
35
by: Stef Mientki | last post by:
hello, I (again) wonder what's the perfect way to store, OS-independent, filepaths ? I can think of something like: - use a relative path if drive is identical to the application (I'm still a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.